1 <?php 2 3 /** 4 * Definition cache decorator class that saves all cache retrievals 5 * to PHP's memory; good for unit tests or circumstances where 6 * there are lots of configuration objects floating around. 7 */ 8 class HTMLPurifier_DefinitionCache_Decorator_Memory extends HTMLPurifier_DefinitionCache_Decorator 9 { 10 /** 11 * @type array 12 */ 13 protected $definitions; 14 15 /** 16 * @type string 17 */ 18 public $name = 'Memory'; 19 20 /** 21 * @return HTMLPurifier_DefinitionCache_Decorator_Memory 22 */ 23 public function copy() 24 { 25 return new HTMLPurifier_DefinitionCache_Decorator_Memory(); 26 } 27 28 /** 29 * @param HTMLPurifier_Definition $def 30 * @param HTMLPurifier_Config $config 31 * @return mixed 32 */ 33 public function add($def, $config) 34 { 35 $status = parent::add($def, $config); 36 if ($status) { 37 $this->definitions[$this->generateKey($config)] = $def; 38 } 39 return $status; 40 } 41 42 /** 43 * @param HTMLPurifier_Definition $def 44 * @param HTMLPurifier_Config $config 45 * @return mixed 46 */ 47 public function set($def, $config) 48 { 49 $status = parent::set($def, $config); 50 if ($status) { 51 $this->definitions[$this->generateKey($config)] = $def; 52 } 53 return $status; 54 } 55 56 /** 57 * @param HTMLPurifier_Definition $def 58 * @param HTMLPurifier_Config $config 59 * @return mixed 60 */ 61 public function replace($def, $config) 62 { 63 $status = parent::replace($def, $config); 64 if ($status) { 65 $this->definitions[$this->generateKey($config)] = $def; 66 } 67 return $status; 68 } 69 70 /** 71 * @param HTMLPurifier_Config $config 72 * @return mixed 73 */ 74 public function get($config) 75 { 76 $key = $this->generateKey($config); 77 if (isset($this->definitions[$key])) { 78 return $this->definitions[$key]; 79 } 80 $this->definitions[$key] = parent::get($config); 81 return $this->definitions[$key]; 82 } 83 } 84 85 // vim: et sw=4 sts=4
title
Description
Body
title
Description
Body
title
Description
Body
title
Body