MDL-11517 reserved word MOD used in table alias in questions backup code
[moodle-pu.git] / lib / htmlpurifier / HTMLPurifier / DefinitionCacheFactory.php
blobacc661828a4ee532f7c05777a7f0a6e1e1cbefb3
1 <?php
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.
11 ');
13 HTMLPurifier_ConfigSchema::defineAllowedValues(
14 'Cache', 'DefinitionImpl', array('Serializer')
17 HTMLPurifier_ConfigSchema::defineAlias(
18 'Core', 'DefinitionCache',
19 'Cache', 'DefinitionImpl'
23 /**
24 * Responsible for creating definition caches.
26 class HTMLPurifier_DefinitionCacheFactory
29 var $caches = array('Serializer' => array());
30 var $decorators = array();
32 /**
33 * Initialize default decorators
35 function setup() {
36 $this->addDecorator('Cleanup');
39 /**
40 * Retrieves an instance of global definition cache factory.
41 * @static
43 function &instance($prototype = null) {
44 static $instance;
45 if ($prototype !== null) {
46 $instance = $prototype;
47 } elseif ($instance === null || $prototype === true) {
48 $instance = new HTMLPurifier_DefinitionCacheFactory();
49 $instance->setup();
51 return $instance;
54 /**
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);
65 return $null;
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
74 unset($cache);
75 $cache = $new_cache;
77 $this->caches[$method][$type] = $cache;
78 return $this->caches[$method][$type];
81 /**
82 * Registers a decorator to add to all new cache objects
83 * @param
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;