diff options
Diffstat (limited to 'extlib/HTMLPurifier/HTMLPurifier/DefinitionCache/Decorator/Memory.php')
-rw-r--r-- | extlib/HTMLPurifier/HTMLPurifier/DefinitionCache/Decorator/Memory.php | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/extlib/HTMLPurifier/HTMLPurifier/DefinitionCache/Decorator/Memory.php b/extlib/HTMLPurifier/HTMLPurifier/DefinitionCache/Decorator/Memory.php new file mode 100644 index 000000000..18f16d32b --- /dev/null +++ b/extlib/HTMLPurifier/HTMLPurifier/DefinitionCache/Decorator/Memory.php @@ -0,0 +1,46 @@ +<?php + +/** + * Definition cache decorator class that saves all cache retrievals + * to PHP's memory; good for unit tests or circumstances where + * there are lots of configuration objects floating around. + */ +class HTMLPurifier_DefinitionCache_Decorator_Memory extends + HTMLPurifier_DefinitionCache_Decorator +{ + + protected $definitions; + public $name = 'Memory'; + + public function copy() { + return new HTMLPurifier_DefinitionCache_Decorator_Memory(); + } + + public function add($def, $config) { + $status = parent::add($def, $config); + if ($status) $this->definitions[$this->generateKey($config)] = $def; + return $status; + } + + public function set($def, $config) { + $status = parent::set($def, $config); + if ($status) $this->definitions[$this->generateKey($config)] = $def; + return $status; + } + + public function replace($def, $config) { + $status = parent::replace($def, $config); + if ($status) $this->definitions[$this->generateKey($config)] = $def; + return $status; + } + + public function get($config) { + $key = $this->generateKey($config); + if (isset($this->definitions[$key])) return $this->definitions[$key]; + $this->definitions[$key] = parent::get($config); + return $this->definitions[$key]; + } + +} + +// vim: et sw=4 sts=4 |