HTMLPurifier_DefinitionCache_Serializer::replace PHP Method

replace() public method

public replace ( HTMLPurifier_Definition $def, HTMLPurifier_Config $config ) : integer | boolean
$def HTMLPurifier_Definition
$config HTMLPurifier_Config
return integer | boolean
    public function replace($def, $config)
    {
        if (!$this->checkDefType($def)) {
            return;
        }
        $file = $this->generateFilePath($config);
        if (!file_exists($file)) {
            return false;
        }
        if (!$this->_prepareDir($config)) {
            return false;
        }
        return $this->_write($file, serialize($def), $config);
    }

Usage Example

 function test_errors()
 {
     $cache = new HTMLPurifier_DefinitionCache_Serializer('Test');
     $def = $this->generateDefinition();
     $def->setup = true;
     $def->type = 'NotTest';
     $config = $this->generateConfigMock('testfoo');
     $this->expectError('Cannot use definition of type NotTest in cache for Test');
     $cache->add($def, $config);
     $this->expectError('Cannot use definition of type NotTest in cache for Test');
     $cache->set($def, $config);
     $this->expectError('Cannot use definition of type NotTest in cache for Test');
     $cache->replace($def, $config);
 }