@@ -9,57 +9,57 @@ |
||
| 9 | 9 | class HTMLPurifier_ConfigSchema_ValidatorAtom |
| 10 | 10 | { |
| 11 | 11 | |
| 12 | - protected $context, $obj, $member, $contents; |
|
| 12 | + protected $context, $obj, $member, $contents; |
|
| 13 | 13 | |
| 14 | - public function __construct($context, $obj, $member) { |
|
| 15 | - $this->context = $context; |
|
| 16 | - $this->obj = $obj; |
|
| 17 | - $this->member = $member; |
|
| 18 | - $this->contents =& $obj->$member; |
|
| 19 | - } |
|
| 14 | + public function __construct($context, $obj, $member) { |
|
| 15 | + $this->context = $context; |
|
| 16 | + $this->obj = $obj; |
|
| 17 | + $this->member = $member; |
|
| 18 | + $this->contents =& $obj->$member; |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - public function assertIsString() { |
|
| 22 | - if (!is_string($this->contents)) $this->error('must be a string'); |
|
| 23 | - return $this; |
|
| 24 | - } |
|
| 21 | + public function assertIsString() { |
|
| 22 | + if (!is_string($this->contents)) $this->error('must be a string'); |
|
| 23 | + return $this; |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - public function assertIsBool() { |
|
| 27 | - if (!is_bool($this->contents)) $this->error('must be a boolean'); |
|
| 28 | - return $this; |
|
| 29 | - } |
|
| 26 | + public function assertIsBool() { |
|
| 27 | + if (!is_bool($this->contents)) $this->error('must be a boolean'); |
|
| 28 | + return $this; |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - public function assertIsArray() { |
|
| 32 | - if (!is_array($this->contents)) $this->error('must be an array'); |
|
| 33 | - return $this; |
|
| 34 | - } |
|
| 31 | + public function assertIsArray() { |
|
| 32 | + if (!is_array($this->contents)) $this->error('must be an array'); |
|
| 33 | + return $this; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - public function assertNotNull() { |
|
| 37 | - if ($this->contents === null) $this->error('must not be null'); |
|
| 38 | - return $this; |
|
| 39 | - } |
|
| 36 | + public function assertNotNull() { |
|
| 37 | + if ($this->contents === null) $this->error('must not be null'); |
|
| 38 | + return $this; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - public function assertAlnum() { |
|
| 42 | - $this->assertIsString(); |
|
| 43 | - if (!ctype_alnum($this->contents)) $this->error('must be alphanumeric'); |
|
| 44 | - return $this; |
|
| 45 | - } |
|
| 41 | + public function assertAlnum() { |
|
| 42 | + $this->assertIsString(); |
|
| 43 | + if (!ctype_alnum($this->contents)) $this->error('must be alphanumeric'); |
|
| 44 | + return $this; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - public function assertNotEmpty() { |
|
| 48 | - if (empty($this->contents)) $this->error('must not be empty'); |
|
| 49 | - return $this; |
|
| 50 | - } |
|
| 47 | + public function assertNotEmpty() { |
|
| 48 | + if (empty($this->contents)) $this->error('must not be empty'); |
|
| 49 | + return $this; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - public function assertIsLookup() { |
|
| 53 | - $this->assertIsArray(); |
|
| 54 | - foreach ($this->contents as $v) { |
|
| 55 | - if ($v !== true) $this->error('must be a lookup array'); |
|
| 56 | - } |
|
| 57 | - return $this; |
|
| 58 | - } |
|
| 52 | + public function assertIsLookup() { |
|
| 53 | + $this->assertIsArray(); |
|
| 54 | + foreach ($this->contents as $v) { |
|
| 55 | + if ($v !== true) $this->error('must be a lookup array'); |
|
| 56 | + } |
|
| 57 | + return $this; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - protected function error($msg) { |
|
| 61 | - throw new HTMLPurifier_ConfigSchema_Exception(ucfirst($this->member) . ' in ' . $this->context . ' ' . $msg); |
|
| 62 | - } |
|
| 60 | + protected function error($msg) { |
|
| 61 | + throw new HTMLPurifier_ConfigSchema_Exception(ucfirst($this->member) . ' in ' . $this->context . ' ' . $msg); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | 64 | } |
| 65 | 65 | |
@@ -19,40 +19,54 @@ |
||
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | public function assertIsString() { |
| 22 | - if (!is_string($this->contents)) $this->error('must be a string'); |
|
| 22 | + if (!is_string($this->contents)) { |
|
| 23 | + $this->error('must be a string'); |
|
| 24 | + } |
|
| 23 | 25 | return $this; |
| 24 | 26 | } |
| 25 | 27 | |
| 26 | 28 | public function assertIsBool() { |
| 27 | - if (!is_bool($this->contents)) $this->error('must be a boolean'); |
|
| 29 | + if (!is_bool($this->contents)) { |
|
| 30 | + $this->error('must be a boolean'); |
|
| 31 | + } |
|
| 28 | 32 | return $this; |
| 29 | 33 | } |
| 30 | 34 | |
| 31 | 35 | public function assertIsArray() { |
| 32 | - if (!is_array($this->contents)) $this->error('must be an array'); |
|
| 36 | + if (!is_array($this->contents)) { |
|
| 37 | + $this->error('must be an array'); |
|
| 38 | + } |
|
| 33 | 39 | return $this; |
| 34 | 40 | } |
| 35 | 41 | |
| 36 | 42 | public function assertNotNull() { |
| 37 | - if ($this->contents === null) $this->error('must not be null'); |
|
| 43 | + if ($this->contents === null) { |
|
| 44 | + $this->error('must not be null'); |
|
| 45 | + } |
|
| 38 | 46 | return $this; |
| 39 | 47 | } |
| 40 | 48 | |
| 41 | 49 | public function assertAlnum() { |
| 42 | 50 | $this->assertIsString(); |
| 43 | - if (!ctype_alnum($this->contents)) $this->error('must be alphanumeric'); |
|
| 51 | + if (!ctype_alnum($this->contents)) { |
|
| 52 | + $this->error('must be alphanumeric'); |
|
| 53 | + } |
|
| 44 | 54 | return $this; |
| 45 | 55 | } |
| 46 | 56 | |
| 47 | 57 | public function assertNotEmpty() { |
| 48 | - if (empty($this->contents)) $this->error('must not be empty'); |
|
| 58 | + if (empty($this->contents)) { |
|
| 59 | + $this->error('must not be empty'); |
|
| 60 | + } |
|
| 49 | 61 | return $this; |
| 50 | 62 | } |
| 51 | 63 | |
| 52 | 64 | public function assertIsLookup() { |
| 53 | 65 | $this->assertIsArray(); |
| 54 | 66 | foreach ($this->contents as $v) { |
| 55 | - if ($v !== true) $this->error('must be a lookup array'); |
|
| 67 | + if ($v !== true) { |
|
| 68 | + $this->error('must be a lookup array'); |
|
| 69 | + } |
|
| 56 | 70 | } |
| 57 | 71 | return $this; |
| 58 | 72 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | $this->context = $context; |
| 16 | 16 | $this->obj = $obj; |
| 17 | 17 | $this->member = $member; |
| 18 | - $this->contents =& $obj->$member; |
|
| 18 | + $this->contents = & $obj->$member; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | public function assertIsString() { |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | protected function error($msg) { |
| 61 | - throw new HTMLPurifier_ConfigSchema_Exception(ucfirst($this->member) . ' in ' . $this->context . ' ' . $msg); |
|
| 61 | + throw new HTMLPurifier_ConfigSchema_Exception(ucfirst($this->member).' in '.$this->context.' '.$msg); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | } |
@@ -6,149 +6,149 @@ |
||
| 6 | 6 | class HTMLPurifier_ContentSets |
| 7 | 7 | { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * List of content set strings (pipe seperators) indexed by name. |
|
| 11 | - */ |
|
| 12 | - public $info = array(); |
|
| 9 | + /** |
|
| 10 | + * List of content set strings (pipe seperators) indexed by name. |
|
| 11 | + */ |
|
| 12 | + public $info = array(); |
|
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * List of content set lookups (element => true) indexed by name. |
|
| 16 | - * @note This is in HTMLPurifier_HTMLDefinition->info_content_sets |
|
| 17 | - */ |
|
| 18 | - public $lookup = array(); |
|
| 14 | + /** |
|
| 15 | + * List of content set lookups (element => true) indexed by name. |
|
| 16 | + * @note This is in HTMLPurifier_HTMLDefinition->info_content_sets |
|
| 17 | + */ |
|
| 18 | + public $lookup = array(); |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Synchronized list of defined content sets (keys of info) |
|
| 22 | - */ |
|
| 23 | - protected $keys = array(); |
|
| 24 | - /** |
|
| 25 | - * Synchronized list of defined content values (values of info) |
|
| 26 | - */ |
|
| 27 | - protected $values = array(); |
|
| 20 | + /** |
|
| 21 | + * Synchronized list of defined content sets (keys of info) |
|
| 22 | + */ |
|
| 23 | + protected $keys = array(); |
|
| 24 | + /** |
|
| 25 | + * Synchronized list of defined content values (values of info) |
|
| 26 | + */ |
|
| 27 | + protected $values = array(); |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Merges in module's content sets, expands identifiers in the content |
|
| 31 | - * sets and populates the keys, values and lookup member variables. |
|
| 32 | - * @param $modules List of HTMLPurifier_HTMLModule |
|
| 33 | - */ |
|
| 34 | - public function __construct($modules) { |
|
| 35 | - if (!is_array($modules)) $modules = array($modules); |
|
| 36 | - // populate content_sets based on module hints |
|
| 37 | - // sorry, no way of overloading |
|
| 38 | - foreach ($modules as $module_i => $module) { |
|
| 39 | - foreach ($module->content_sets as $key => $value) { |
|
| 40 | - $temp = $this->convertToLookup($value); |
|
| 41 | - if (isset($this->lookup[$key])) { |
|
| 42 | - // add it into the existing content set |
|
| 43 | - $this->lookup[$key] = array_merge($this->lookup[$key], $temp); |
|
| 44 | - } else { |
|
| 45 | - $this->lookup[$key] = $temp; |
|
| 46 | - } |
|
| 47 | - } |
|
| 48 | - } |
|
| 49 | - $old_lookup = false; |
|
| 50 | - while ($old_lookup !== $this->lookup) { |
|
| 51 | - $old_lookup = $this->lookup; |
|
| 52 | - foreach ($this->lookup as $i => $set) { |
|
| 53 | - $add = array(); |
|
| 54 | - foreach ($set as $element => $x) { |
|
| 55 | - if (isset($this->lookup[$element])) { |
|
| 56 | - $add += $this->lookup[$element]; |
|
| 57 | - unset($this->lookup[$i][$element]); |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - $this->lookup[$i] += $add; |
|
| 61 | - } |
|
| 62 | - } |
|
| 29 | + /** |
|
| 30 | + * Merges in module's content sets, expands identifiers in the content |
|
| 31 | + * sets and populates the keys, values and lookup member variables. |
|
| 32 | + * @param $modules List of HTMLPurifier_HTMLModule |
|
| 33 | + */ |
|
| 34 | + public function __construct($modules) { |
|
| 35 | + if (!is_array($modules)) $modules = array($modules); |
|
| 36 | + // populate content_sets based on module hints |
|
| 37 | + // sorry, no way of overloading |
|
| 38 | + foreach ($modules as $module_i => $module) { |
|
| 39 | + foreach ($module->content_sets as $key => $value) { |
|
| 40 | + $temp = $this->convertToLookup($value); |
|
| 41 | + if (isset($this->lookup[$key])) { |
|
| 42 | + // add it into the existing content set |
|
| 43 | + $this->lookup[$key] = array_merge($this->lookup[$key], $temp); |
|
| 44 | + } else { |
|
| 45 | + $this->lookup[$key] = $temp; |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | + $old_lookup = false; |
|
| 50 | + while ($old_lookup !== $this->lookup) { |
|
| 51 | + $old_lookup = $this->lookup; |
|
| 52 | + foreach ($this->lookup as $i => $set) { |
|
| 53 | + $add = array(); |
|
| 54 | + foreach ($set as $element => $x) { |
|
| 55 | + if (isset($this->lookup[$element])) { |
|
| 56 | + $add += $this->lookup[$element]; |
|
| 57 | + unset($this->lookup[$i][$element]); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + $this->lookup[$i] += $add; |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - foreach ($this->lookup as $key => $lookup) { |
|
| 65 | - $this->info[$key] = implode(' | ', array_keys($lookup)); |
|
| 66 | - } |
|
| 67 | - $this->keys = array_keys($this->info); |
|
| 68 | - $this->values = array_values($this->info); |
|
| 69 | - } |
|
| 64 | + foreach ($this->lookup as $key => $lookup) { |
|
| 65 | + $this->info[$key] = implode(' | ', array_keys($lookup)); |
|
| 66 | + } |
|
| 67 | + $this->keys = array_keys($this->info); |
|
| 68 | + $this->values = array_values($this->info); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Accepts a definition; generates and assigns a ChildDef for it |
|
| 73 | - * @param $def HTMLPurifier_ElementDef reference |
|
| 74 | - * @param $module Module that defined the ElementDef |
|
| 75 | - */ |
|
| 76 | - public function generateChildDef(&$def, $module) { |
|
| 77 | - if (!empty($def->child)) return; // already done! |
|
| 78 | - $content_model = $def->content_model; |
|
| 79 | - if (is_string($content_model)) { |
|
| 80 | - // Assume that $this->keys is alphanumeric |
|
| 81 | - $def->content_model = preg_replace_callback( |
|
| 82 | - '/\b(' . implode('|', $this->keys) . ')\b/', |
|
| 83 | - array($this, 'generateChildDefCallback'), |
|
| 84 | - $content_model |
|
| 85 | - ); |
|
| 86 | - //$def->content_model = str_replace( |
|
| 87 | - // $this->keys, $this->values, $content_model); |
|
| 88 | - } |
|
| 89 | - $def->child = $this->getChildDef($def, $module); |
|
| 90 | - } |
|
| 71 | + /** |
|
| 72 | + * Accepts a definition; generates and assigns a ChildDef for it |
|
| 73 | + * @param $def HTMLPurifier_ElementDef reference |
|
| 74 | + * @param $module Module that defined the ElementDef |
|
| 75 | + */ |
|
| 76 | + public function generateChildDef(&$def, $module) { |
|
| 77 | + if (!empty($def->child)) return; // already done! |
|
| 78 | + $content_model = $def->content_model; |
|
| 79 | + if (is_string($content_model)) { |
|
| 80 | + // Assume that $this->keys is alphanumeric |
|
| 81 | + $def->content_model = preg_replace_callback( |
|
| 82 | + '/\b(' . implode('|', $this->keys) . ')\b/', |
|
| 83 | + array($this, 'generateChildDefCallback'), |
|
| 84 | + $content_model |
|
| 85 | + ); |
|
| 86 | + //$def->content_model = str_replace( |
|
| 87 | + // $this->keys, $this->values, $content_model); |
|
| 88 | + } |
|
| 89 | + $def->child = $this->getChildDef($def, $module); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - public function generateChildDefCallback($matches) { |
|
| 93 | - return $this->info[$matches[0]]; |
|
| 94 | - } |
|
| 92 | + public function generateChildDefCallback($matches) { |
|
| 93 | + return $this->info[$matches[0]]; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * Instantiates a ChildDef based on content_model and content_model_type |
|
| 98 | - * member variables in HTMLPurifier_ElementDef |
|
| 99 | - * @note This will also defer to modules for custom HTMLPurifier_ChildDef |
|
| 100 | - * subclasses that need content set expansion |
|
| 101 | - * @param $def HTMLPurifier_ElementDef to have ChildDef extracted |
|
| 102 | - * @return HTMLPurifier_ChildDef corresponding to ElementDef |
|
| 103 | - */ |
|
| 104 | - public function getChildDef($def, $module) { |
|
| 105 | - $value = $def->content_model; |
|
| 106 | - if (is_object($value)) { |
|
| 107 | - trigger_error( |
|
| 108 | - 'Literal object child definitions should be stored in '. |
|
| 109 | - 'ElementDef->child not ElementDef->content_model', |
|
| 110 | - E_USER_NOTICE |
|
| 111 | - ); |
|
| 112 | - return $value; |
|
| 113 | - } |
|
| 114 | - switch ($def->content_model_type) { |
|
| 115 | - case 'required': |
|
| 116 | - return new HTMLPurifier_ChildDef_Required($value); |
|
| 117 | - case 'optional': |
|
| 118 | - return new HTMLPurifier_ChildDef_Optional($value); |
|
| 119 | - case 'empty': |
|
| 120 | - return new HTMLPurifier_ChildDef_Empty(); |
|
| 121 | - case 'custom': |
|
| 122 | - return new HTMLPurifier_ChildDef_Custom($value); |
|
| 123 | - } |
|
| 124 | - // defer to its module |
|
| 125 | - $return = false; |
|
| 126 | - if ($module->defines_child_def) { // save a func call |
|
| 127 | - $return = $module->getChildDef($def); |
|
| 128 | - } |
|
| 129 | - if ($return !== false) return $return; |
|
| 130 | - // error-out |
|
| 131 | - trigger_error( |
|
| 132 | - 'Could not determine which ChildDef class to instantiate', |
|
| 133 | - E_USER_ERROR |
|
| 134 | - ); |
|
| 135 | - return false; |
|
| 136 | - } |
|
| 96 | + /** |
|
| 97 | + * Instantiates a ChildDef based on content_model and content_model_type |
|
| 98 | + * member variables in HTMLPurifier_ElementDef |
|
| 99 | + * @note This will also defer to modules for custom HTMLPurifier_ChildDef |
|
| 100 | + * subclasses that need content set expansion |
|
| 101 | + * @param $def HTMLPurifier_ElementDef to have ChildDef extracted |
|
| 102 | + * @return HTMLPurifier_ChildDef corresponding to ElementDef |
|
| 103 | + */ |
|
| 104 | + public function getChildDef($def, $module) { |
|
| 105 | + $value = $def->content_model; |
|
| 106 | + if (is_object($value)) { |
|
| 107 | + trigger_error( |
|
| 108 | + 'Literal object child definitions should be stored in '. |
|
| 109 | + 'ElementDef->child not ElementDef->content_model', |
|
| 110 | + E_USER_NOTICE |
|
| 111 | + ); |
|
| 112 | + return $value; |
|
| 113 | + } |
|
| 114 | + switch ($def->content_model_type) { |
|
| 115 | + case 'required': |
|
| 116 | + return new HTMLPurifier_ChildDef_Required($value); |
|
| 117 | + case 'optional': |
|
| 118 | + return new HTMLPurifier_ChildDef_Optional($value); |
|
| 119 | + case 'empty': |
|
| 120 | + return new HTMLPurifier_ChildDef_Empty(); |
|
| 121 | + case 'custom': |
|
| 122 | + return new HTMLPurifier_ChildDef_Custom($value); |
|
| 123 | + } |
|
| 124 | + // defer to its module |
|
| 125 | + $return = false; |
|
| 126 | + if ($module->defines_child_def) { // save a func call |
|
| 127 | + $return = $module->getChildDef($def); |
|
| 128 | + } |
|
| 129 | + if ($return !== false) return $return; |
|
| 130 | + // error-out |
|
| 131 | + trigger_error( |
|
| 132 | + 'Could not determine which ChildDef class to instantiate', |
|
| 133 | + E_USER_ERROR |
|
| 134 | + ); |
|
| 135 | + return false; |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | - /** |
|
| 139 | - * Converts a string list of elements separated by pipes into |
|
| 140 | - * a lookup array. |
|
| 141 | - * @param $string List of elements |
|
| 142 | - * @return Lookup array of elements |
|
| 143 | - */ |
|
| 144 | - protected function convertToLookup($string) { |
|
| 145 | - $array = explode('|', str_replace(' ', '', $string)); |
|
| 146 | - $ret = array(); |
|
| 147 | - foreach ($array as $i => $k) { |
|
| 148 | - $ret[$k] = true; |
|
| 149 | - } |
|
| 150 | - return $ret; |
|
| 151 | - } |
|
| 138 | + /** |
|
| 139 | + * Converts a string list of elements separated by pipes into |
|
| 140 | + * a lookup array. |
|
| 141 | + * @param $string List of elements |
|
| 142 | + * @return Lookup array of elements |
|
| 143 | + */ |
|
| 144 | + protected function convertToLookup($string) { |
|
| 145 | + $array = explode('|', str_replace(' ', '', $string)); |
|
| 146 | + $ret = array(); |
|
| 147 | + foreach ($array as $i => $k) { |
|
| 148 | + $ret[$k] = true; |
|
| 149 | + } |
|
| 150 | + return $ret; |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | 153 | } |
| 154 | 154 | |
@@ -32,7 +32,9 @@ discard block |
||
| 32 | 32 | * @param $modules List of HTMLPurifier_HTMLModule |
| 33 | 33 | */ |
| 34 | 34 | public function __construct($modules) { |
| 35 | - if (!is_array($modules)) $modules = array($modules); |
|
| 35 | + if (!is_array($modules)) { |
|
| 36 | + $modules = array($modules); |
|
| 37 | + } |
|
| 36 | 38 | // populate content_sets based on module hints |
| 37 | 39 | // sorry, no way of overloading |
| 38 | 40 | foreach ($modules as $module_i => $module) { |
@@ -74,7 +76,10 @@ discard block |
||
| 74 | 76 | * @param $module Module that defined the ElementDef |
| 75 | 77 | */ |
| 76 | 78 | public function generateChildDef(&$def, $module) { |
| 77 | - if (!empty($def->child)) return; // already done! |
|
| 79 | + if (!empty($def->child)) { |
|
| 80 | + return; |
|
| 81 | + } |
|
| 82 | + // already done! |
|
| 78 | 83 | $content_model = $def->content_model; |
| 79 | 84 | if (is_string($content_model)) { |
| 80 | 85 | // Assume that $this->keys is alphanumeric |
@@ -126,7 +131,9 @@ discard block |
||
| 126 | 131 | if ($module->defines_child_def) { // save a func call |
| 127 | 132 | $return = $module->getChildDef($def); |
| 128 | 133 | } |
| 129 | - if ($return !== false) return $return; |
|
| 134 | + if ($return !== false) { |
|
| 135 | + return $return; |
|
| 136 | + } |
|
| 130 | 137 | // error-out |
| 131 | 138 | trigger_error( |
| 132 | 139 | 'Could not determine which ChildDef class to instantiate', |
@@ -79,7 +79,7 @@ |
||
| 79 | 79 | if (is_string($content_model)) { |
| 80 | 80 | // Assume that $this->keys is alphanumeric |
| 81 | 81 | $def->content_model = preg_replace_callback( |
| 82 | - '/\b(' . implode('|', $this->keys) . ')\b/', |
|
| 82 | + '/\b('.implode('|', $this->keys).')\b/', |
|
| 83 | 83 | array($this, 'generateChildDefCallback'), |
| 84 | 84 | $content_model |
| 85 | 85 | ); |
@@ -10,72 +10,72 @@ |
||
| 10 | 10 | class HTMLPurifier_Context |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * Private array that stores the references. |
|
| 15 | - */ |
|
| 16 | - private $_storage = array(); |
|
| 13 | + /** |
|
| 14 | + * Private array that stores the references. |
|
| 15 | + */ |
|
| 16 | + private $_storage = array(); |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Registers a variable into the context. |
|
| 20 | - * @param $name String name |
|
| 21 | - * @param $ref Reference to variable to be registered |
|
| 22 | - */ |
|
| 23 | - public function register($name, &$ref) { |
|
| 24 | - if (isset($this->_storage[$name])) { |
|
| 25 | - trigger_error("Name $name produces collision, cannot re-register", |
|
| 26 | - E_USER_ERROR); |
|
| 27 | - return; |
|
| 28 | - } |
|
| 29 | - $this->_storage[$name] =& $ref; |
|
| 30 | - } |
|
| 18 | + /** |
|
| 19 | + * Registers a variable into the context. |
|
| 20 | + * @param $name String name |
|
| 21 | + * @param $ref Reference to variable to be registered |
|
| 22 | + */ |
|
| 23 | + public function register($name, &$ref) { |
|
| 24 | + if (isset($this->_storage[$name])) { |
|
| 25 | + trigger_error("Name $name produces collision, cannot re-register", |
|
| 26 | + E_USER_ERROR); |
|
| 27 | + return; |
|
| 28 | + } |
|
| 29 | + $this->_storage[$name] =& $ref; |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Retrieves a variable reference from the context. |
|
| 34 | - * @param $name String name |
|
| 35 | - * @param $ignore_error Boolean whether or not to ignore error |
|
| 36 | - */ |
|
| 37 | - public function &get($name, $ignore_error = false) { |
|
| 38 | - if (!isset($this->_storage[$name])) { |
|
| 39 | - if (!$ignore_error) { |
|
| 40 | - trigger_error("Attempted to retrieve non-existent variable $name", |
|
| 41 | - E_USER_ERROR); |
|
| 42 | - } |
|
| 43 | - $var = null; // so we can return by reference |
|
| 44 | - return $var; |
|
| 45 | - } |
|
| 46 | - return $this->_storage[$name]; |
|
| 47 | - } |
|
| 32 | + /** |
|
| 33 | + * Retrieves a variable reference from the context. |
|
| 34 | + * @param $name String name |
|
| 35 | + * @param $ignore_error Boolean whether or not to ignore error |
|
| 36 | + */ |
|
| 37 | + public function &get($name, $ignore_error = false) { |
|
| 38 | + if (!isset($this->_storage[$name])) { |
|
| 39 | + if (!$ignore_error) { |
|
| 40 | + trigger_error("Attempted to retrieve non-existent variable $name", |
|
| 41 | + E_USER_ERROR); |
|
| 42 | + } |
|
| 43 | + $var = null; // so we can return by reference |
|
| 44 | + return $var; |
|
| 45 | + } |
|
| 46 | + return $this->_storage[$name]; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Destorys a variable in the context. |
|
| 51 | - * @param $name String name |
|
| 52 | - */ |
|
| 53 | - public function destroy($name) { |
|
| 54 | - if (!isset($this->_storage[$name])) { |
|
| 55 | - trigger_error("Attempted to destroy non-existent variable $name", |
|
| 56 | - E_USER_ERROR); |
|
| 57 | - return; |
|
| 58 | - } |
|
| 59 | - unset($this->_storage[$name]); |
|
| 60 | - } |
|
| 49 | + /** |
|
| 50 | + * Destorys a variable in the context. |
|
| 51 | + * @param $name String name |
|
| 52 | + */ |
|
| 53 | + public function destroy($name) { |
|
| 54 | + if (!isset($this->_storage[$name])) { |
|
| 55 | + trigger_error("Attempted to destroy non-existent variable $name", |
|
| 56 | + E_USER_ERROR); |
|
| 57 | + return; |
|
| 58 | + } |
|
| 59 | + unset($this->_storage[$name]); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Checks whether or not the variable exists. |
|
| 64 | - * @param $name String name |
|
| 65 | - */ |
|
| 66 | - public function exists($name) { |
|
| 67 | - return isset($this->_storage[$name]); |
|
| 68 | - } |
|
| 62 | + /** |
|
| 63 | + * Checks whether or not the variable exists. |
|
| 64 | + * @param $name String name |
|
| 65 | + */ |
|
| 66 | + public function exists($name) { |
|
| 67 | + return isset($this->_storage[$name]); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Loads a series of variables from an associative array |
|
| 72 | - * @param $context_array Assoc array of variables to load |
|
| 73 | - */ |
|
| 74 | - public function loadArray($context_array) { |
|
| 75 | - foreach ($context_array as $key => $discard) { |
|
| 76 | - $this->register($key, $context_array[$key]); |
|
| 77 | - } |
|
| 78 | - } |
|
| 70 | + /** |
|
| 71 | + * Loads a series of variables from an associative array |
|
| 72 | + * @param $context_array Assoc array of variables to load |
|
| 73 | + */ |
|
| 74 | + public function loadArray($context_array) { |
|
| 75 | + foreach ($context_array as $key => $discard) { |
|
| 76 | + $this->register($key, $context_array[$key]); |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | 80 | } |
| 81 | 81 | |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | E_USER_ERROR); |
| 27 | 27 | return; |
| 28 | 28 | } |
| 29 | - $this->_storage[$name] =& $ref; |
|
| 29 | + $this->_storage[$name] = & $ref; |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | /** |
@@ -7,43 +7,43 @@ |
||
| 7 | 7 | abstract class HTMLPurifier_Definition |
| 8 | 8 | { |
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * Has setup() been called yet? |
|
| 12 | - */ |
|
| 13 | - public $setup = false; |
|
| 14 | - |
|
| 15 | - /** |
|
| 16 | - * If true, write out the final definition object to the cache after |
|
| 17 | - * setup. This will be true only if all invocations to get a raw |
|
| 18 | - * definition object are also optimized. This does not cause file |
|
| 19 | - * system thrashing because on subsequent calls the cached object |
|
| 20 | - * is used and any writes to the raw definition object are short |
|
| 21 | - * circuited. See enduser-customize.html for the high-level |
|
| 22 | - * picture. |
|
| 23 | - */ |
|
| 24 | - public $optimized = null; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * What type of definition is it? |
|
| 28 | - */ |
|
| 29 | - public $type; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Sets up the definition object into the final form, something |
|
| 33 | - * not done by the constructor |
|
| 34 | - * @param $config HTMLPurifier_Config instance |
|
| 35 | - */ |
|
| 36 | - abstract protected function doSetup($config); |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Setup function that aborts if already setup |
|
| 40 | - * @param $config HTMLPurifier_Config instance |
|
| 41 | - */ |
|
| 42 | - public function setup($config) { |
|
| 43 | - if ($this->setup) return; |
|
| 44 | - $this->setup = true; |
|
| 45 | - $this->doSetup($config); |
|
| 46 | - } |
|
| 10 | + /** |
|
| 11 | + * Has setup() been called yet? |
|
| 12 | + */ |
|
| 13 | + public $setup = false; |
|
| 14 | + |
|
| 15 | + /** |
|
| 16 | + * If true, write out the final definition object to the cache after |
|
| 17 | + * setup. This will be true only if all invocations to get a raw |
|
| 18 | + * definition object are also optimized. This does not cause file |
|
| 19 | + * system thrashing because on subsequent calls the cached object |
|
| 20 | + * is used and any writes to the raw definition object are short |
|
| 21 | + * circuited. See enduser-customize.html for the high-level |
|
| 22 | + * picture. |
|
| 23 | + */ |
|
| 24 | + public $optimized = null; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * What type of definition is it? |
|
| 28 | + */ |
|
| 29 | + public $type; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Sets up the definition object into the final form, something |
|
| 33 | + * not done by the constructor |
|
| 34 | + * @param $config HTMLPurifier_Config instance |
|
| 35 | + */ |
|
| 36 | + abstract protected function doSetup($config); |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Setup function that aborts if already setup |
|
| 40 | + * @param $config HTMLPurifier_Config instance |
|
| 41 | + */ |
|
| 42 | + public function setup($config) { |
|
| 43 | + if ($this->setup) return; |
|
| 44 | + $this->setup = true; |
|
| 45 | + $this->doSetup($config); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | 48 | } |
| 49 | 49 | |
@@ -40,7 +40,9 @@ |
||
| 40 | 40 | * @param $config HTMLPurifier_Config instance |
| 41 | 41 | */ |
| 42 | 42 | public function setup($config) { |
| 43 | - if ($this->setup) return; |
|
| 43 | + if ($this->setup) { |
|
| 44 | + return; |
|
| 45 | + } |
|
| 44 | 46 | $this->setup = true; |
| 45 | 47 | $this->doSetup($config); |
| 46 | 48 | } |
@@ -11,97 +11,97 @@ |
||
| 11 | 11 | abstract class HTMLPurifier_DefinitionCache |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - public $type; |
|
| 14 | + public $type; |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @param $name Type of definition objects this instance of the |
|
| 18 | - * cache will handle. |
|
| 19 | - */ |
|
| 20 | - public function __construct($type) { |
|
| 21 | - $this->type = $type; |
|
| 22 | - } |
|
| 16 | + /** |
|
| 17 | + * @param $name Type of definition objects this instance of the |
|
| 18 | + * cache will handle. |
|
| 19 | + */ |
|
| 20 | + public function __construct($type) { |
|
| 21 | + $this->type = $type; |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Generates a unique identifier for a particular configuration |
|
| 26 | - * @param Instance of HTMLPurifier_Config |
|
| 27 | - */ |
|
| 28 | - public function generateKey($config) { |
|
| 29 | - return $config->version . ',' . // possibly replace with function calls |
|
| 30 | - $config->getBatchSerial($this->type) . ',' . |
|
| 31 | - $config->get($this->type . '.DefinitionRev'); |
|
| 32 | - } |
|
| 24 | + /** |
|
| 25 | + * Generates a unique identifier for a particular configuration |
|
| 26 | + * @param Instance of HTMLPurifier_Config |
|
| 27 | + */ |
|
| 28 | + public function generateKey($config) { |
|
| 29 | + return $config->version . ',' . // possibly replace with function calls |
|
| 30 | + $config->getBatchSerial($this->type) . ',' . |
|
| 31 | + $config->get($this->type . '.DefinitionRev'); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Tests whether or not a key is old with respect to the configuration's |
|
| 36 | - * version and revision number. |
|
| 37 | - * @param $key Key to test |
|
| 38 | - * @param $config Instance of HTMLPurifier_Config to test against |
|
| 39 | - */ |
|
| 40 | - public function isOld($key, $config) { |
|
| 41 | - if (substr_count($key, ',') < 2) return true; |
|
| 42 | - list($version, $hash, $revision) = explode(',', $key, 3); |
|
| 43 | - $compare = version_compare($version, $config->version); |
|
| 44 | - // version mismatch, is always old |
|
| 45 | - if ($compare != 0) return true; |
|
| 46 | - // versions match, ids match, check revision number |
|
| 47 | - if ( |
|
| 48 | - $hash == $config->getBatchSerial($this->type) && |
|
| 49 | - $revision < $config->get($this->type . '.DefinitionRev') |
|
| 50 | - ) return true; |
|
| 51 | - return false; |
|
| 52 | - } |
|
| 34 | + /** |
|
| 35 | + * Tests whether or not a key is old with respect to the configuration's |
|
| 36 | + * version and revision number. |
|
| 37 | + * @param $key Key to test |
|
| 38 | + * @param $config Instance of HTMLPurifier_Config to test against |
|
| 39 | + */ |
|
| 40 | + public function isOld($key, $config) { |
|
| 41 | + if (substr_count($key, ',') < 2) return true; |
|
| 42 | + list($version, $hash, $revision) = explode(',', $key, 3); |
|
| 43 | + $compare = version_compare($version, $config->version); |
|
| 44 | + // version mismatch, is always old |
|
| 45 | + if ($compare != 0) return true; |
|
| 46 | + // versions match, ids match, check revision number |
|
| 47 | + if ( |
|
| 48 | + $hash == $config->getBatchSerial($this->type) && |
|
| 49 | + $revision < $config->get($this->type . '.DefinitionRev') |
|
| 50 | + ) return true; |
|
| 51 | + return false; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Checks if a definition's type jives with the cache's type |
|
| 56 | - * @note Throws an error on failure |
|
| 57 | - * @param $def Definition object to check |
|
| 58 | - * @return Boolean true if good, false if not |
|
| 59 | - */ |
|
| 60 | - public function checkDefType($def) { |
|
| 61 | - if ($def->type !== $this->type) { |
|
| 62 | - trigger_error("Cannot use definition of type {$def->type} in cache for {$this->type}"); |
|
| 63 | - return false; |
|
| 64 | - } |
|
| 65 | - return true; |
|
| 66 | - } |
|
| 54 | + /** |
|
| 55 | + * Checks if a definition's type jives with the cache's type |
|
| 56 | + * @note Throws an error on failure |
|
| 57 | + * @param $def Definition object to check |
|
| 58 | + * @return Boolean true if good, false if not |
|
| 59 | + */ |
|
| 60 | + public function checkDefType($def) { |
|
| 61 | + if ($def->type !== $this->type) { |
|
| 62 | + trigger_error("Cannot use definition of type {$def->type} in cache for {$this->type}"); |
|
| 63 | + return false; |
|
| 64 | + } |
|
| 65 | + return true; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Adds a definition object to the cache |
|
| 70 | - */ |
|
| 71 | - abstract public function add($def, $config); |
|
| 68 | + /** |
|
| 69 | + * Adds a definition object to the cache |
|
| 70 | + */ |
|
| 71 | + abstract public function add($def, $config); |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Unconditionally saves a definition object to the cache |
|
| 75 | - */ |
|
| 76 | - abstract public function set($def, $config); |
|
| 73 | + /** |
|
| 74 | + * Unconditionally saves a definition object to the cache |
|
| 75 | + */ |
|
| 76 | + abstract public function set($def, $config); |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Replace an object in the cache |
|
| 80 | - */ |
|
| 81 | - abstract public function replace($def, $config); |
|
| 78 | + /** |
|
| 79 | + * Replace an object in the cache |
|
| 80 | + */ |
|
| 81 | + abstract public function replace($def, $config); |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Retrieves a definition object from the cache |
|
| 85 | - */ |
|
| 86 | - abstract public function get($config); |
|
| 83 | + /** |
|
| 84 | + * Retrieves a definition object from the cache |
|
| 85 | + */ |
|
| 86 | + abstract public function get($config); |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Removes a definition object to the cache |
|
| 90 | - */ |
|
| 91 | - abstract public function remove($config); |
|
| 88 | + /** |
|
| 89 | + * Removes a definition object to the cache |
|
| 90 | + */ |
|
| 91 | + abstract public function remove($config); |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * Clears all objects from cache |
|
| 95 | - */ |
|
| 96 | - abstract public function flush($config); |
|
| 93 | + /** |
|
| 94 | + * Clears all objects from cache |
|
| 95 | + */ |
|
| 96 | + abstract public function flush($config); |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * Clears all expired (older version or revision) objects from cache |
|
| 100 | - * @note Be carefuly implementing this method as flush. Flush must |
|
| 101 | - * not interfere with other Definition types, and cleanup() |
|
| 102 | - * should not be repeatedly called by userland code. |
|
| 103 | - */ |
|
| 104 | - abstract public function cleanup($config); |
|
| 98 | + /** |
|
| 99 | + * Clears all expired (older version or revision) objects from cache |
|
| 100 | + * @note Be carefuly implementing this method as flush. Flush must |
|
| 101 | + * not interfere with other Definition types, and cleanup() |
|
| 102 | + * should not be repeatedly called by userland code. |
|
| 103 | + */ |
|
| 104 | + abstract public function cleanup($config); |
|
| 105 | 105 | |
| 106 | 106 | } |
| 107 | 107 | |
@@ -38,16 +38,22 @@ |
||
| 38 | 38 | * @param $config Instance of HTMLPurifier_Config to test against |
| 39 | 39 | */ |
| 40 | 40 | public function isOld($key, $config) { |
| 41 | - if (substr_count($key, ',') < 2) return true; |
|
| 41 | + if (substr_count($key, ',') < 2) { |
|
| 42 | + return true; |
|
| 43 | + } |
|
| 42 | 44 | list($version, $hash, $revision) = explode(',', $key, 3); |
| 43 | 45 | $compare = version_compare($version, $config->version); |
| 44 | 46 | // version mismatch, is always old |
| 45 | - if ($compare != 0) return true; |
|
| 47 | + if ($compare != 0) { |
|
| 48 | + return true; |
|
| 49 | + } |
|
| 46 | 50 | // versions match, ids match, check revision number |
| 47 | 51 | if ( |
| 48 | 52 | $hash == $config->getBatchSerial($this->type) && |
| 49 | 53 | $revision < $config->get($this->type . '.DefinitionRev') |
| 50 | - ) return true; |
|
| 54 | + ) { |
|
| 55 | + return true; |
|
| 56 | + } |
|
| 51 | 57 | return false; |
| 52 | 58 | } |
| 53 | 59 | |
@@ -26,9 +26,9 @@ discard block |
||
| 26 | 26 | * @param Instance of HTMLPurifier_Config |
| 27 | 27 | */ |
| 28 | 28 | public function generateKey($config) { |
| 29 | - return $config->version . ',' . // possibly replace with function calls |
|
| 30 | - $config->getBatchSerial($this->type) . ',' . |
|
| 31 | - $config->get($this->type . '.DefinitionRev'); |
|
| 29 | + return $config->version.','.// possibly replace with function calls |
|
| 30 | + $config->getBatchSerial($this->type).','. |
|
| 31 | + $config->get($this->type.'.DefinitionRev'); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | // versions match, ids match, check revision number |
| 47 | 47 | if ( |
| 48 | 48 | $hash == $config->getBatchSerial($this->type) && |
| 49 | - $revision < $config->get($this->type . '.DefinitionRev') |
|
| 49 | + $revision < $config->get($this->type.'.DefinitionRev') |
|
| 50 | 50 | ) return true; |
| 51 | 51 | return false; |
| 52 | 52 | } |
@@ -3,59 +3,59 @@ |
||
| 3 | 3 | class HTMLPurifier_DefinitionCache_Decorator extends HTMLPurifier_DefinitionCache |
| 4 | 4 | { |
| 5 | 5 | |
| 6 | - /** |
|
| 7 | - * Cache object we are decorating |
|
| 8 | - */ |
|
| 9 | - public $cache; |
|
| 10 | - |
|
| 11 | - public function __construct() {} |
|
| 12 | - |
|
| 13 | - /** |
|
| 14 | - * Lazy decorator function |
|
| 15 | - * @param $cache Reference to cache object to decorate |
|
| 16 | - */ |
|
| 17 | - public function decorate(&$cache) { |
|
| 18 | - $decorator = $this->copy(); |
|
| 19 | - // reference is necessary for mocks in PHP 4 |
|
| 20 | - $decorator->cache =& $cache; |
|
| 21 | - $decorator->type = $cache->type; |
|
| 22 | - return $decorator; |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * Cross-compatible clone substitute |
|
| 27 | - */ |
|
| 28 | - public function copy() { |
|
| 29 | - return new HTMLPurifier_DefinitionCache_Decorator(); |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - public function add($def, $config) { |
|
| 33 | - return $this->cache->add($def, $config); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - public function set($def, $config) { |
|
| 37 | - return $this->cache->set($def, $config); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - public function replace($def, $config) { |
|
| 41 | - return $this->cache->replace($def, $config); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - public function get($config) { |
|
| 45 | - return $this->cache->get($config); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - public function remove($config) { |
|
| 49 | - return $this->cache->remove($config); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - public function flush($config) { |
|
| 53 | - return $this->cache->flush($config); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - public function cleanup($config) { |
|
| 57 | - return $this->cache->cleanup($config); |
|
| 58 | - } |
|
| 6 | + /** |
|
| 7 | + * Cache object we are decorating |
|
| 8 | + */ |
|
| 9 | + public $cache; |
|
| 10 | + |
|
| 11 | + public function __construct() {} |
|
| 12 | + |
|
| 13 | + /** |
|
| 14 | + * Lazy decorator function |
|
| 15 | + * @param $cache Reference to cache object to decorate |
|
| 16 | + */ |
|
| 17 | + public function decorate(&$cache) { |
|
| 18 | + $decorator = $this->copy(); |
|
| 19 | + // reference is necessary for mocks in PHP 4 |
|
| 20 | + $decorator->cache =& $cache; |
|
| 21 | + $decorator->type = $cache->type; |
|
| 22 | + return $decorator; |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * Cross-compatible clone substitute |
|
| 27 | + */ |
|
| 28 | + public function copy() { |
|
| 29 | + return new HTMLPurifier_DefinitionCache_Decorator(); |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + public function add($def, $config) { |
|
| 33 | + return $this->cache->add($def, $config); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + public function set($def, $config) { |
|
| 37 | + return $this->cache->set($def, $config); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + public function replace($def, $config) { |
|
| 41 | + return $this->cache->replace($def, $config); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + public function get($config) { |
|
| 45 | + return $this->cache->get($config); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + public function remove($config) { |
|
| 49 | + return $this->cache->remove($config); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + public function flush($config) { |
|
| 53 | + return $this->cache->flush($config); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + public function cleanup($config) { |
|
| 57 | + return $this->cache->cleanup($config); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | 60 | } |
| 61 | 61 | |
@@ -17,7 +17,7 @@ |
||
| 17 | 17 | public function decorate(&$cache) { |
| 18 | 18 | $decorator = $this->copy(); |
| 19 | 19 | // reference is necessary for mocks in PHP 4 |
| 20 | - $decorator->cache =& $cache; |
|
| 20 | + $decorator->cache = & $cache; |
|
| 21 | 21 | $decorator->type = $cache->type; |
| 22 | 22 | return $decorator; |
| 23 | 23 | } |
@@ -5,38 +5,38 @@ |
||
| 5 | 5 | * whenever there is a cache miss. |
| 6 | 6 | */ |
| 7 | 7 | class HTMLPurifier_DefinitionCache_Decorator_Cleanup extends |
| 8 | - HTMLPurifier_DefinitionCache_Decorator |
|
| 8 | + HTMLPurifier_DefinitionCache_Decorator |
|
| 9 | 9 | { |
| 10 | 10 | |
| 11 | - public $name = 'Cleanup'; |
|
| 12 | - |
|
| 13 | - public function copy() { |
|
| 14 | - return new HTMLPurifier_DefinitionCache_Decorator_Cleanup(); |
|
| 15 | - } |
|
| 16 | - |
|
| 17 | - public function add($def, $config) { |
|
| 18 | - $status = parent::add($def, $config); |
|
| 19 | - if (!$status) parent::cleanup($config); |
|
| 20 | - return $status; |
|
| 21 | - } |
|
| 22 | - |
|
| 23 | - public function set($def, $config) { |
|
| 24 | - $status = parent::set($def, $config); |
|
| 25 | - if (!$status) parent::cleanup($config); |
|
| 26 | - return $status; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - public function replace($def, $config) { |
|
| 30 | - $status = parent::replace($def, $config); |
|
| 31 | - if (!$status) parent::cleanup($config); |
|
| 32 | - return $status; |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - public function get($config) { |
|
| 36 | - $ret = parent::get($config); |
|
| 37 | - if (!$ret) parent::cleanup($config); |
|
| 38 | - return $ret; |
|
| 39 | - } |
|
| 11 | + public $name = 'Cleanup'; |
|
| 12 | + |
|
| 13 | + public function copy() { |
|
| 14 | + return new HTMLPurifier_DefinitionCache_Decorator_Cleanup(); |
|
| 15 | + } |
|
| 16 | + |
|
| 17 | + public function add($def, $config) { |
|
| 18 | + $status = parent::add($def, $config); |
|
| 19 | + if (!$status) parent::cleanup($config); |
|
| 20 | + return $status; |
|
| 21 | + } |
|
| 22 | + |
|
| 23 | + public function set($def, $config) { |
|
| 24 | + $status = parent::set($def, $config); |
|
| 25 | + if (!$status) parent::cleanup($config); |
|
| 26 | + return $status; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + public function replace($def, $config) { |
|
| 30 | + $status = parent::replace($def, $config); |
|
| 31 | + if (!$status) parent::cleanup($config); |
|
| 32 | + return $status; |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + public function get($config) { |
|
| 36 | + $ret = parent::get($config); |
|
| 37 | + if (!$ret) parent::cleanup($config); |
|
| 38 | + return $ret; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | 41 | } |
| 42 | 42 | |
@@ -16,25 +16,33 @@ |
||
| 16 | 16 | |
| 17 | 17 | public function add($def, $config) { |
| 18 | 18 | $status = parent::add($def, $config); |
| 19 | - if (!$status) parent::cleanup($config); |
|
| 19 | + if (!$status) { |
|
| 20 | + parent::cleanup($config); |
|
| 21 | + } |
|
| 20 | 22 | return $status; |
| 21 | 23 | } |
| 22 | 24 | |
| 23 | 25 | public function set($def, $config) { |
| 24 | 26 | $status = parent::set($def, $config); |
| 25 | - if (!$status) parent::cleanup($config); |
|
| 27 | + if (!$status) { |
|
| 28 | + parent::cleanup($config); |
|
| 29 | + } |
|
| 26 | 30 | return $status; |
| 27 | 31 | } |
| 28 | 32 | |
| 29 | 33 | public function replace($def, $config) { |
| 30 | 34 | $status = parent::replace($def, $config); |
| 31 | - if (!$status) parent::cleanup($config); |
|
| 35 | + if (!$status) { |
|
| 36 | + parent::cleanup($config); |
|
| 37 | + } |
|
| 32 | 38 | return $status; |
| 33 | 39 | } |
| 34 | 40 | |
| 35 | 41 | public function get($config) { |
| 36 | 42 | $ret = parent::get($config); |
| 37 | - if (!$ret) parent::cleanup($config); |
|
| 43 | + if (!$ret) { |
|
| 44 | + parent::cleanup($config); |
|
| 45 | + } |
|
| 38 | 46 | return $ret; |
| 39 | 47 | } |
| 40 | 48 | |
@@ -6,40 +6,40 @@ |
||
| 6 | 6 | * there are lots of configuration objects floating around. |
| 7 | 7 | */ |
| 8 | 8 | class HTMLPurifier_DefinitionCache_Decorator_Memory extends |
| 9 | - HTMLPurifier_DefinitionCache_Decorator |
|
| 9 | + HTMLPurifier_DefinitionCache_Decorator |
|
| 10 | 10 | { |
| 11 | 11 | |
| 12 | - protected $definitions; |
|
| 13 | - public $name = 'Memory'; |
|
| 14 | - |
|
| 15 | - public function copy() { |
|
| 16 | - return new HTMLPurifier_DefinitionCache_Decorator_Memory(); |
|
| 17 | - } |
|
| 18 | - |
|
| 19 | - public function add($def, $config) { |
|
| 20 | - $status = parent::add($def, $config); |
|
| 21 | - if ($status) $this->definitions[$this->generateKey($config)] = $def; |
|
| 22 | - return $status; |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - public function set($def, $config) { |
|
| 26 | - $status = parent::set($def, $config); |
|
| 27 | - if ($status) $this->definitions[$this->generateKey($config)] = $def; |
|
| 28 | - return $status; |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - public function replace($def, $config) { |
|
| 32 | - $status = parent::replace($def, $config); |
|
| 33 | - if ($status) $this->definitions[$this->generateKey($config)] = $def; |
|
| 34 | - return $status; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - public function get($config) { |
|
| 38 | - $key = $this->generateKey($config); |
|
| 39 | - if (isset($this->definitions[$key])) return $this->definitions[$key]; |
|
| 40 | - $this->definitions[$key] = parent::get($config); |
|
| 41 | - return $this->definitions[$key]; |
|
| 42 | - } |
|
| 12 | + protected $definitions; |
|
| 13 | + public $name = 'Memory'; |
|
| 14 | + |
|
| 15 | + public function copy() { |
|
| 16 | + return new HTMLPurifier_DefinitionCache_Decorator_Memory(); |
|
| 17 | + } |
|
| 18 | + |
|
| 19 | + public function add($def, $config) { |
|
| 20 | + $status = parent::add($def, $config); |
|
| 21 | + if ($status) $this->definitions[$this->generateKey($config)] = $def; |
|
| 22 | + return $status; |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + public function set($def, $config) { |
|
| 26 | + $status = parent::set($def, $config); |
|
| 27 | + if ($status) $this->definitions[$this->generateKey($config)] = $def; |
|
| 28 | + return $status; |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + public function replace($def, $config) { |
|
| 32 | + $status = parent::replace($def, $config); |
|
| 33 | + if ($status) $this->definitions[$this->generateKey($config)] = $def; |
|
| 34 | + return $status; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + public function get($config) { |
|
| 38 | + $key = $this->generateKey($config); |
|
| 39 | + if (isset($this->definitions[$key])) return $this->definitions[$key]; |
|
| 40 | + $this->definitions[$key] = parent::get($config); |
|
| 41 | + return $this->definitions[$key]; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | 44 | } |
| 45 | 45 | |
@@ -18,25 +18,33 @@ |
||
| 18 | 18 | |
| 19 | 19 | public function add($def, $config) { |
| 20 | 20 | $status = parent::add($def, $config); |
| 21 | - if ($status) $this->definitions[$this->generateKey($config)] = $def; |
|
| 21 | + if ($status) { |
|
| 22 | + $this->definitions[$this->generateKey($config)] = $def; |
|
| 23 | + } |
|
| 22 | 24 | return $status; |
| 23 | 25 | } |
| 24 | 26 | |
| 25 | 27 | public function set($def, $config) { |
| 26 | 28 | $status = parent::set($def, $config); |
| 27 | - if ($status) $this->definitions[$this->generateKey($config)] = $def; |
|
| 29 | + if ($status) { |
|
| 30 | + $this->definitions[$this->generateKey($config)] = $def; |
|
| 31 | + } |
|
| 28 | 32 | return $status; |
| 29 | 33 | } |
| 30 | 34 | |
| 31 | 35 | public function replace($def, $config) { |
| 32 | 36 | $status = parent::replace($def, $config); |
| 33 | - if ($status) $this->definitions[$this->generateKey($config)] = $def; |
|
| 37 | + if ($status) { |
|
| 38 | + $this->definitions[$this->generateKey($config)] = $def; |
|
| 39 | + } |
|
| 34 | 40 | return $status; |
| 35 | 41 | } |
| 36 | 42 | |
| 37 | 43 | public function get($config) { |
| 38 | 44 | $key = $this->generateKey($config); |
| 39 | - if (isset($this->definitions[$key])) return $this->definitions[$key]; |
|
| 45 | + if (isset($this->definitions[$key])) { |
|
| 46 | + return $this->definitions[$key]; |
|
| 47 | + } |
|
| 40 | 48 | $this->definitions[$key] = parent::get($config); |
| 41 | 49 | return $this->definitions[$key]; |
| 42 | 50 | } |
@@ -6,33 +6,33 @@ |
||
| 6 | 6 | class HTMLPurifier_DefinitionCache_Null extends HTMLPurifier_DefinitionCache |
| 7 | 7 | { |
| 8 | 8 | |
| 9 | - public function add($def, $config) { |
|
| 10 | - return false; |
|
| 11 | - } |
|
| 9 | + public function add($def, $config) { |
|
| 10 | + return false; |
|
| 11 | + } |
|
| 12 | 12 | |
| 13 | - public function set($def, $config) { |
|
| 14 | - return false; |
|
| 15 | - } |
|
| 13 | + public function set($def, $config) { |
|
| 14 | + return false; |
|
| 15 | + } |
|
| 16 | 16 | |
| 17 | - public function replace($def, $config) { |
|
| 18 | - return false; |
|
| 19 | - } |
|
| 17 | + public function replace($def, $config) { |
|
| 18 | + return false; |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - public function remove($config) { |
|
| 22 | - return false; |
|
| 23 | - } |
|
| 21 | + public function remove($config) { |
|
| 22 | + return false; |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - public function get($config) { |
|
| 26 | - return false; |
|
| 27 | - } |
|
| 25 | + public function get($config) { |
|
| 26 | + return false; |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - public function flush($config) { |
|
| 30 | - return false; |
|
| 31 | - } |
|
| 29 | + public function flush($config) { |
|
| 30 | + return false; |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - public function cleanup($config) { |
|
| 34 | - return false; |
|
| 35 | - } |
|
| 33 | + public function cleanup($config) { |
|
| 34 | + return false; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | 37 | } |
| 38 | 38 | |