ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
HTMLPurifier_DefinitionCacheFactory Class Reference

Responsible for creating definition caches. More...

+ Collaboration diagram for HTMLPurifier_DefinitionCacheFactory:

Public Member Functions

 setup ()
 Initialize default decorators. More...
 
 register ($short, $long)
 Registers a new definition cache object. More...
 
 create ($type, $config)
 Factory method that creates a cache object based on configuration. More...
 
 addDecorator ($decorator)
 Registers a decorator to add to all new cache objects. More...
 

Static Public Member Functions

static instance ($prototype=null)
 Retrieves an instance of global definition cache factory. More...
 

Protected Attributes

 $caches = array('Serializer' => array())
 array More...
 
 $implementations = array()
 array More...
 
 $decorators = array()
 HTMLPurifier_DefinitionCache_Decorator[] More...
 

Detailed Description

Responsible for creating definition caches.

Definition at line 6 of file DefinitionCacheFactory.php.

Member Function Documentation

◆ addDecorator()

HTMLPurifier_DefinitionCacheFactory::addDecorator (   $decorator)

Registers a decorator to add to all new cache objects.

Parameters
HTMLPurifier_DefinitionCache_Decorator | string$decoratorAn instance or the name of a decorator

Definition at line 96 of file DefinitionCacheFactory.php.

Referenced by setup().

97  {
98  if (is_string($decorator)) {
99  $class = "HTMLPurifier_DefinitionCache_Decorator_$decorator";
100  $decorator = new $class;
101  }
102  $this->decorators[$decorator->name] = $decorator;
103  }
+ Here is the caller graph for this function:

◆ create()

HTMLPurifier_DefinitionCacheFactory::create (   $type,
  $config 
)

Factory method that creates a cache object based on configuration.

Parameters
string$typeName of definitions handled by cache
HTMLPurifier_Config$configConfig instance
Returns
mixed

Definition at line 64 of file DefinitionCacheFactory.php.

References $config, and $type.

65  {
66  $method = $config->get('Cache.DefinitionImpl');
67  if ($method === null) {
69  }
70  if (!empty($this->caches[$method][$type])) {
71  return $this->caches[$method][$type];
72  }
73  if (isset($this->implementations[$method]) &&
74  class_exists($class = $this->implementations[$method], false)) {
75  $cache = new $class($type);
76  } else {
77  if ($method != 'Serializer') {
78  trigger_error("Unrecognized DefinitionCache $method, using Serializer instead", E_USER_WARNING);
79  }
80  $cache = new HTMLPurifier_DefinitionCache_Serializer($type);
81  }
82  foreach ($this->decorators as $decorator) {
83  $new_cache = $decorator->decorate($cache);
84  // prevent infinite recursion in PHP 4
85  unset($cache);
86  $cache = $new_cache;
87  }
88  $this->caches[$method][$type] = $cache;
89  return $this->caches[$method][$type];
90  }
$config
Definition: bootstrap.php:15
$type
Null cache object to use when no caching is on.
Definition: Null.php:6

◆ instance()

static HTMLPurifier_DefinitionCacheFactory::instance (   $prototype = null)
static

Retrieves an instance of global definition cache factory.

Parameters
HTMLPurifier_DefinitionCacheFactory$prototype
Returns
HTMLPurifier_DefinitionCacheFactory

Definition at line 36 of file DefinitionCacheFactory.php.

Referenced by HTMLPurifier_Config\getDefinition().

37  {
38  static $instance;
39  if ($prototype !== null) {
40  $instance = $prototype;
41  } elseif ($instance === null || $prototype === true) {
42  $instance = new HTMLPurifier_DefinitionCacheFactory();
43  $instance->setup();
44  }
45  return $instance;
46  }
Responsible for creating definition caches.
+ Here is the caller graph for this function:

◆ register()

HTMLPurifier_DefinitionCacheFactory::register (   $short,
  $long 
)

Registers a new definition cache object.

Parameters
string$shortShort name of cache object, for reference
string$longFull class name of cache object, for construction

Definition at line 53 of file DefinitionCacheFactory.php.

54  {
55  $this->implementations[$short] = $long;
56  }

◆ setup()

HTMLPurifier_DefinitionCacheFactory::setup ( )

Initialize default decorators.

Definition at line 26 of file DefinitionCacheFactory.php.

References addDecorator().

27  {
28  $this->addDecorator('Cleanup');
29  }
addDecorator($decorator)
Registers a decorator to add to all new cache objects.
+ Here is the call graph for this function:

Field Documentation

◆ $caches

HTMLPurifier_DefinitionCacheFactory::$caches = array('Serializer' => array())
protected

array

Definition at line 11 of file DefinitionCacheFactory.php.

◆ $decorators

HTMLPurifier_DefinitionCacheFactory::$decorators = array()
protected

◆ $implementations

HTMLPurifier_DefinitionCacheFactory::$implementations = array()
protected

array

Definition at line 16 of file DefinitionCacheFactory.php.


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