ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
DefinitionCacheFactory.php
Go to the documentation of this file.
1<?php
2
7{
11 protected $caches = array('Serializer' => array());
12
16 protected $implementations = array();
17
21 protected $decorators = array();
22
26 public function setup()
27 {
28 $this->addDecorator('Cleanup');
29 }
30
36 public static function instance($prototype = null)
37 {
38 static $instance;
39 if ($prototype !== null) {
40 $instance = $prototype;
41 } elseif ($instance === null || $prototype === true) {
43 $instance->setup();
44 }
45 return $instance;
46 }
47
53 public function register($short, $long)
54 {
55 $this->implementations[$short] = $long;
56 }
57
64 public function create($type, $config)
65 {
66 $method = $config->get('Cache.DefinitionImpl');
67 if ($method === null) {
68 return new HTMLPurifier_DefinitionCache_Null($type);
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 }
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 }
91
96 public function addDecorator($decorator)
97 {
98 if (is_string($decorator)) {
99 $class = "HTMLPurifier_DefinitionCache_Decorator_$decorator";
100 $decorator = new $class;
101 }
102 $this->decorators[$decorator->name] = $decorator;
103 }
104}
105
106// vim: et sw=4 sts=4
Responsible for creating definition caches.
$decorators
@type HTMLPurifier_DefinitionCache_Decorator[]
setup()
Initialize default decorators.
addDecorator($decorator)
Registers a decorator to add to all new cache objects.
create($type, $config)
Factory method that creates a cache object based on configuration.
static instance($prototype=null)
Retrieves an instance of global definition cache factory.
Null cache object to use when no caching is on.
Definition: Null.php:7