3 require_once 'HTMLPurifier/DefinitionCache.php';
5 HTMLPurifier_ConfigSchema
::define(
6 'Cache', 'DefinitionImpl', 'Serializer', 'string/null', '
7 This directive defines which method to use when caching definitions,
8 the complex data-type that makes HTML Purifier tick. Set to null
9 to disable caching (not recommended, as you will see a definite
10 performance degradation). This directive has been available since 2.0.0.
13 HTMLPurifier_ConfigSchema
::defineAllowedValues(
14 'Cache', 'DefinitionImpl', array('Serializer')
17 HTMLPurifier_ConfigSchema
::defineAlias(
18 'Core', 'DefinitionCache',
19 'Cache', 'DefinitionImpl'
24 * Responsible for creating definition caches.
26 class HTMLPurifier_DefinitionCacheFactory
29 var $caches = array('Serializer' => array());
30 var $decorators = array();
33 * Initialize default decorators
36 $this->addDecorator('Cleanup');
40 * Retrieves an instance of global definition cache factory.
43 function &instance($prototype = null) {
45 if ($prototype !== null) {
46 $instance = $prototype;
47 } elseif ($instance === null ||
$prototype === true) {
48 $instance = new HTMLPurifier_DefinitionCacheFactory();
55 * Factory method that creates a cache object based on configuration
56 * @param $name Name of definitions handled by cache
57 * @param $config Instance of HTMLPurifier_Config
59 function &create($type, $config) {
60 // only one implementation as for right now, $config will
61 // be used to determine implementation
62 $method = $config->get('Cache', 'DefinitionImpl');
63 if ($method === null) {
64 $null = new HTMLPurifier_DefinitionCache_Null($type);
67 if (!empty($this->caches
[$method][$type])) {
68 return $this->caches
[$method][$type];
70 $cache = new HTMLPurifier_DefinitionCache_Serializer($type);
71 foreach ($this->decorators
as $decorator) {
72 $new_cache = $decorator->decorate($cache);
73 // prevent infinite recursion in PHP 4
77 $this->caches
[$method][$type] = $cache;
78 return $this->caches
[$method][$type];
82 * Registers a decorator to add to all new cache objects
85 function addDecorator($decorator) {
86 if (is_string($decorator)) {
87 $class = "HTMLPurifier_DefinitionCache_Decorator_$decorator";
88 $decorator = new $class;
90 $this->decorators
[$decorator->name
] = $decorator;