ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
HTMLPurifier_DefinitionCache Class Reference

Abstract class representing Definition cache managers that implements useful common methods and is a factory. More...

+ Inheritance diagram for HTMLPurifier_DefinitionCache:
+ Collaboration diagram for HTMLPurifier_DefinitionCache:

Public Member Functions

 __construct ($type)
 
 generateKey ($config)
 Generates a unique identifier for a particular configuration. More...
 
 isOld ($key, $config)
 Tests whether or not a key is old with respect to the configuration's version and revision number. More...
 
 checkDefType ($def)
 Checks if a definition's type jives with the cache's type. More...
 
 add ($def, $config)
 Adds a definition object to the cache. More...
 
 set ($def, $config)
 Unconditionally saves a definition object to the cache. More...
 
 replace ($def, $config)
 Replace an object in the cache. More...
 
 get ($config)
 Retrieves a definition object from the cache. More...
 
 remove ($config)
 Removes a definition object to the cache. More...
 
 flush ($config)
 Clears all objects from cache. More...
 
 cleanup ($config)
 Clears all expired (older version or revision) objects from cache. More...
 

Data Fields

 $type
 @type string More...
 

Detailed Description

Abstract class representing Definition cache managers that implements useful common methods and is a factory.

Todo:

Create a separate maintenance file advanced users can use to cache their custom HTMLDefinition, which can be loaded via a configuration directive

Implement memcached

Definition at line 11 of file DefinitionCache.php.

Constructor & Destructor Documentation

◆ __construct()

HTMLPurifier_DefinitionCache::__construct (   $type)
Parameters
string$typeType of definition objects this instance of the cache will handle.

Definition at line 22 of file DefinitionCache.php.

23 {
24 $this->type = $type;
25 }

References $type.

Member Function Documentation

◆ add()

HTMLPurifier_DefinitionCache::add (   $def,
  $config 
)
abstract

◆ checkDefType()

HTMLPurifier_DefinitionCache::checkDefType (   $def)

Checks if a definition's type jives with the cache's type.

Note
Throws an error on failure
Parameters
HTMLPurifier_Definition$defDefinition object to check
Returns
bool true if good, false if not

Definition at line 71 of file DefinitionCache.php.

72 {
73 if ($def->type !== $this->type) {
74 trigger_error("Cannot use definition of type {$def->type} in cache for {$this->type}");
75 return false;
76 }
77 return true;
78 }

Referenced by HTMLPurifier_DefinitionCache_Serializer\add(), HTMLPurifier_DefinitionCache_Serializer\replace(), and HTMLPurifier_DefinitionCache_Serializer\set().

+ Here is the caller graph for this function:

◆ cleanup()

HTMLPurifier_DefinitionCache::cleanup (   $config)
abstract

Clears all expired (older version or revision) objects from cache.

Note
Be carefuly implementing this method as flush. Flush must not interfere with other Definition types, and cleanup() should not be repeatedly called by userland code.
Parameters
HTMLPurifier_Config$config

Reimplemented in HTMLPurifier_DefinitionCache_Decorator, HTMLPurifier_DefinitionCache_Null, and HTMLPurifier_DefinitionCache_Serializer.

◆ flush()

HTMLPurifier_DefinitionCache::flush (   $config)
abstract

◆ generateKey()

HTMLPurifier_DefinitionCache::generateKey (   $config)

Generates a unique identifier for a particular configuration.

Parameters
HTMLPurifier_Config$configInstance of HTMLPurifier_Config
Returns
string

Definition at line 32 of file DefinitionCache.php.

33 {
34 return $config->version . ',' . // possibly replace with function calls
35 $config->getBatchSerial($this->type) . ',' .
36 $config->get($this->type . '.DefinitionRev');
37 }

Referenced by HTMLPurifier_DefinitionCache_Decorator_Memory\add(), HTMLPurifier_DefinitionCache_Serializer\generateFilePath(), HTMLPurifier_DefinitionCache_Decorator_Memory\get(), HTMLPurifier_DefinitionCache_Decorator_Memory\replace(), and HTMLPurifier_DefinitionCache_Decorator_Memory\set().

+ Here is the caller graph for this function:

◆ get()

HTMLPurifier_DefinitionCache::get (   $config)
abstract

◆ isOld()

HTMLPurifier_DefinitionCache::isOld (   $key,
  $config 
)

Tests whether or not a key is old with respect to the configuration's version and revision number.

Parameters
string$keyKey to test
HTMLPurifier_Config$configInstance of HTMLPurifier_Config to test against
Returns
bool

Definition at line 46 of file DefinitionCache.php.

47 {
48 if (substr_count($key, ',') < 2) {
49 return true;
50 }
51 list($version, $hash, $revision) = explode(',', $key, 3);
52 $compare = version_compare($version, $config->version);
53 // version mismatch, is always old
54 if ($compare != 0) {
55 return true;
56 }
57 // versions match, ids match, check revision number
58 if ($hash == $config->getBatchSerial($this->type) &&
59 $revision < $config->get($this->type . '.DefinitionRev')) {
60 return true;
61 }
62 return false;
63 }

Referenced by HTMLPurifier_DefinitionCache_Serializer\cleanup().

+ Here is the caller graph for this function:

◆ remove()

HTMLPurifier_DefinitionCache::remove (   $config)
abstract

Removes a definition object to the cache.

Parameters
HTMLPurifier_Config$config

Reimplemented in HTMLPurifier_DefinitionCache_Decorator, HTMLPurifier_DefinitionCache_Null, and HTMLPurifier_DefinitionCache_Serializer.

◆ replace()

◆ set()

HTMLPurifier_DefinitionCache::set (   $def,
  $config 
)
abstract

Field Documentation

◆ $type

HTMLPurifier_DefinitionCache::$type

@type string

Definition at line 16 of file DefinitionCache.php.

Referenced by __construct(), and HTMLPurifier_DefinitionCache_Serializer\generateDirectoryPath().


The documentation for this class was generated from the following file: