File indexing completed on 2025-01-26 05:29:06

0001 <?php
0002 
0003 /**
0004  * Definition cache decorator class that saves all cache retrievals
0005  * to PHP's memory; good for unit tests or circumstances where
0006  * there are lots of configuration objects floating around.
0007  */
0008 class HTMLPurifier_DefinitionCache_Decorator_Memory extends HTMLPurifier_DefinitionCache_Decorator
0009 {
0010     /**
0011      * @type array
0012      */
0013     protected $definitions;
0014 
0015     /**
0016      * @type string
0017      */
0018     public $name = 'Memory';
0019 
0020     /**
0021      * @return HTMLPurifier_DefinitionCache_Decorator_Memory
0022      */
0023     public function copy()
0024     {
0025         return new HTMLPurifier_DefinitionCache_Decorator_Memory();
0026     }
0027 
0028     /**
0029      * @param HTMLPurifier_Definition $def
0030      * @param HTMLPurifier_Config $config
0031      * @return mixed
0032      */
0033     public function add($def, $config)
0034     {
0035         $status = parent::add($def, $config);
0036         if ($status) {
0037             $this->definitions[$this->generateKey($config)] = $def;
0038         }
0039         return $status;
0040     }
0041 
0042     /**
0043      * @param HTMLPurifier_Definition $def
0044      * @param HTMLPurifier_Config $config
0045      * @return mixed
0046      */
0047     public function set($def, $config)
0048     {
0049         $status = parent::set($def, $config);
0050         if ($status) {
0051             $this->definitions[$this->generateKey($config)] = $def;
0052         }
0053         return $status;
0054     }
0055 
0056     /**
0057      * @param HTMLPurifier_Definition $def
0058      * @param HTMLPurifier_Config $config
0059      * @return mixed
0060      */
0061     public function replace($def, $config)
0062     {
0063         $status = parent::replace($def, $config);
0064         if ($status) {
0065             $this->definitions[$this->generateKey($config)] = $def;
0066         }
0067         return $status;
0068     }
0069 
0070     /**
0071      * @param HTMLPurifier_Config $config
0072      * @return mixed
0073      */
0074     public function get($config)
0075     {
0076         $key = $this->generateKey($config);
0077         if (isset($this->definitions[$key])) {
0078             return $this->definitions[$key];
0079         }
0080         $this->definitions[$key] = parent::get($config);
0081         return $this->definitions[$key];
0082     }
0083 }
0084 
0085 // vim: et sw=4 sts=4