@@ -11,195 +11,195 @@ |
||
11 | 11 | class HTMLPurifier_ConfigSchema_Validator |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * Easy to access global objects. |
|
16 | - */ |
|
17 | - protected $interchange, $aliases; |
|
18 | - |
|
19 | - /** |
|
20 | - * Context-stack to provide easy to read error messages. |
|
21 | - */ |
|
22 | - protected $context = array(); |
|
23 | - |
|
24 | - /** |
|
25 | - * HTMLPurifier_VarParser to test default's type. |
|
26 | - */ |
|
27 | - protected $parser; |
|
28 | - |
|
29 | - public function __construct() { |
|
30 | - $this->parser = new HTMLPurifier_VarParser(); |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * Validates a fully-formed interchange object. Throws an |
|
35 | - * HTMLPurifier_ConfigSchema_Exception if there's a problem. |
|
36 | - */ |
|
37 | - public function validate($interchange) { |
|
38 | - $this->interchange = $interchange; |
|
39 | - $this->aliases = array(); |
|
40 | - // PHP is a bit lax with integer <=> string conversions in |
|
41 | - // arrays, so we don't use the identical !== comparison |
|
42 | - foreach ($interchange->directives as $i => $directive) { |
|
43 | - $id = $directive->id->toString(); |
|
44 | - if ($i != $id) $this->error(false, "Integrity violation: key '$i' does not match internal id '$id'"); |
|
45 | - $this->validateDirective($directive); |
|
46 | - } |
|
47 | - return true; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * Validates a HTMLPurifier_ConfigSchema_Interchange_Id object. |
|
52 | - */ |
|
53 | - public function validateId($id) { |
|
54 | - $id_string = $id->toString(); |
|
55 | - $this->context[] = "id '$id_string'"; |
|
56 | - if (!$id instanceof HTMLPurifier_ConfigSchema_Interchange_Id) { |
|
57 | - // handled by InterchangeBuilder |
|
58 | - $this->error(false, 'is not an instance of HTMLPurifier_ConfigSchema_Interchange_Id'); |
|
59 | - } |
|
60 | - // keys are now unconstrained (we might want to narrow down to A-Za-z0-9.) |
|
61 | - // we probably should check that it has at least one namespace |
|
62 | - $this->with($id, 'key') |
|
63 | - ->assertNotEmpty() |
|
64 | - ->assertIsString(); // implicit assertIsString handled by InterchangeBuilder |
|
65 | - array_pop($this->context); |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Validates a HTMLPurifier_ConfigSchema_Interchange_Directive object. |
|
70 | - */ |
|
71 | - public function validateDirective($d) { |
|
72 | - $id = $d->id->toString(); |
|
73 | - $this->context[] = "directive '$id'"; |
|
74 | - $this->validateId($d->id); |
|
75 | - |
|
76 | - $this->with($d, 'description') |
|
77 | - ->assertNotEmpty(); |
|
78 | - |
|
79 | - // BEGIN - handled by InterchangeBuilder |
|
80 | - $this->with($d, 'type') |
|
81 | - ->assertNotEmpty(); |
|
82 | - $this->with($d, 'typeAllowsNull') |
|
83 | - ->assertIsBool(); |
|
84 | - try { |
|
85 | - // This also tests validity of $d->type |
|
86 | - $this->parser->parse($d->default, $d->type, $d->typeAllowsNull); |
|
87 | - } catch (HTMLPurifier_VarParserException $e) { |
|
88 | - $this->error('default', 'had error: ' . $e->getMessage()); |
|
89 | - } |
|
90 | - // END - handled by InterchangeBuilder |
|
91 | - |
|
92 | - if (!is_null($d->allowed) || !empty($d->valueAliases)) { |
|
93 | - // allowed and valueAliases require that we be dealing with |
|
94 | - // strings, so check for that early. |
|
95 | - $d_int = HTMLPurifier_VarParser::$types[$d->type]; |
|
96 | - if (!isset(HTMLPurifier_VarParser::$stringTypes[$d_int])) { |
|
97 | - $this->error('type', 'must be a string type when used with allowed or value aliases'); |
|
98 | - } |
|
99 | - } |
|
100 | - |
|
101 | - $this->validateDirectiveAllowed($d); |
|
102 | - $this->validateDirectiveValueAliases($d); |
|
103 | - $this->validateDirectiveAliases($d); |
|
104 | - |
|
105 | - array_pop($this->context); |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Extra validation if $allowed member variable of |
|
110 | - * HTMLPurifier_ConfigSchema_Interchange_Directive is defined. |
|
111 | - */ |
|
112 | - public function validateDirectiveAllowed($d) { |
|
113 | - if (is_null($d->allowed)) return; |
|
114 | - $this->with($d, 'allowed') |
|
115 | - ->assertNotEmpty() |
|
116 | - ->assertIsLookup(); // handled by InterchangeBuilder |
|
117 | - if (is_string($d->default) && !isset($d->allowed[$d->default])) { |
|
118 | - $this->error('default', 'must be an allowed value'); |
|
119 | - } |
|
120 | - $this->context[] = 'allowed'; |
|
121 | - foreach ($d->allowed as $val => $x) { |
|
122 | - if (!is_string($val)) $this->error("value $val", 'must be a string'); |
|
123 | - } |
|
124 | - array_pop($this->context); |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Extra validation if $valueAliases member variable of |
|
129 | - * HTMLPurifier_ConfigSchema_Interchange_Directive is defined. |
|
130 | - */ |
|
131 | - public function validateDirectiveValueAliases($d) { |
|
132 | - if (is_null($d->valueAliases)) return; |
|
133 | - $this->with($d, 'valueAliases') |
|
134 | - ->assertIsArray(); // handled by InterchangeBuilder |
|
135 | - $this->context[] = 'valueAliases'; |
|
136 | - foreach ($d->valueAliases as $alias => $real) { |
|
137 | - if (!is_string($alias)) $this->error("alias $alias", 'must be a string'); |
|
138 | - if (!is_string($real)) $this->error("alias target $real from alias '$alias'", 'must be a string'); |
|
139 | - if ($alias === $real) { |
|
140 | - $this->error("alias '$alias'", "must not be an alias to itself"); |
|
141 | - } |
|
142 | - } |
|
143 | - if (!is_null($d->allowed)) { |
|
144 | - foreach ($d->valueAliases as $alias => $real) { |
|
145 | - if (isset($d->allowed[$alias])) { |
|
146 | - $this->error("alias '$alias'", 'must not be an allowed value'); |
|
147 | - } elseif (!isset($d->allowed[$real])) { |
|
148 | - $this->error("alias '$alias'", 'must be an alias to an allowed value'); |
|
149 | - } |
|
150 | - } |
|
151 | - } |
|
152 | - array_pop($this->context); |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Extra validation if $aliases member variable of |
|
157 | - * HTMLPurifier_ConfigSchema_Interchange_Directive is defined. |
|
158 | - */ |
|
159 | - public function validateDirectiveAliases($d) { |
|
160 | - $this->with($d, 'aliases') |
|
161 | - ->assertIsArray(); // handled by InterchangeBuilder |
|
162 | - $this->context[] = 'aliases'; |
|
163 | - foreach ($d->aliases as $alias) { |
|
164 | - $this->validateId($alias); |
|
165 | - $s = $alias->toString(); |
|
166 | - if (isset($this->interchange->directives[$s])) { |
|
167 | - $this->error("alias '$s'", 'collides with another directive'); |
|
168 | - } |
|
169 | - if (isset($this->aliases[$s])) { |
|
170 | - $other_directive = $this->aliases[$s]; |
|
171 | - $this->error("alias '$s'", "collides with alias for directive '$other_directive'"); |
|
172 | - } |
|
173 | - $this->aliases[$s] = $d->id->toString(); |
|
174 | - } |
|
175 | - array_pop($this->context); |
|
176 | - } |
|
177 | - |
|
178 | - // protected helper functions |
|
179 | - |
|
180 | - /** |
|
181 | - * Convenience function for generating HTMLPurifier_ConfigSchema_ValidatorAtom |
|
182 | - * for validating simple member variables of objects. |
|
183 | - */ |
|
184 | - protected function with($obj, $member) { |
|
185 | - return new HTMLPurifier_ConfigSchema_ValidatorAtom($this->getFormattedContext(), $obj, $member); |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Emits an error, providing helpful context. |
|
190 | - */ |
|
191 | - protected function error($target, $msg) { |
|
192 | - if ($target !== false) $prefix = ucfirst($target) . ' in ' . $this->getFormattedContext(); |
|
193 | - else $prefix = ucfirst($this->getFormattedContext()); |
|
194 | - throw new HTMLPurifier_ConfigSchema_Exception(trim($prefix . ' ' . $msg)); |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * Returns a formatted context string. |
|
199 | - */ |
|
200 | - protected function getFormattedContext() { |
|
201 | - return implode(' in ', array_reverse($this->context)); |
|
202 | - } |
|
14 | + /** |
|
15 | + * Easy to access global objects. |
|
16 | + */ |
|
17 | + protected $interchange, $aliases; |
|
18 | + |
|
19 | + /** |
|
20 | + * Context-stack to provide easy to read error messages. |
|
21 | + */ |
|
22 | + protected $context = array(); |
|
23 | + |
|
24 | + /** |
|
25 | + * HTMLPurifier_VarParser to test default's type. |
|
26 | + */ |
|
27 | + protected $parser; |
|
28 | + |
|
29 | + public function __construct() { |
|
30 | + $this->parser = new HTMLPurifier_VarParser(); |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * Validates a fully-formed interchange object. Throws an |
|
35 | + * HTMLPurifier_ConfigSchema_Exception if there's a problem. |
|
36 | + */ |
|
37 | + public function validate($interchange) { |
|
38 | + $this->interchange = $interchange; |
|
39 | + $this->aliases = array(); |
|
40 | + // PHP is a bit lax with integer <=> string conversions in |
|
41 | + // arrays, so we don't use the identical !== comparison |
|
42 | + foreach ($interchange->directives as $i => $directive) { |
|
43 | + $id = $directive->id->toString(); |
|
44 | + if ($i != $id) $this->error(false, "Integrity violation: key '$i' does not match internal id '$id'"); |
|
45 | + $this->validateDirective($directive); |
|
46 | + } |
|
47 | + return true; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * Validates a HTMLPurifier_ConfigSchema_Interchange_Id object. |
|
52 | + */ |
|
53 | + public function validateId($id) { |
|
54 | + $id_string = $id->toString(); |
|
55 | + $this->context[] = "id '$id_string'"; |
|
56 | + if (!$id instanceof HTMLPurifier_ConfigSchema_Interchange_Id) { |
|
57 | + // handled by InterchangeBuilder |
|
58 | + $this->error(false, 'is not an instance of HTMLPurifier_ConfigSchema_Interchange_Id'); |
|
59 | + } |
|
60 | + // keys are now unconstrained (we might want to narrow down to A-Za-z0-9.) |
|
61 | + // we probably should check that it has at least one namespace |
|
62 | + $this->with($id, 'key') |
|
63 | + ->assertNotEmpty() |
|
64 | + ->assertIsString(); // implicit assertIsString handled by InterchangeBuilder |
|
65 | + array_pop($this->context); |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * Validates a HTMLPurifier_ConfigSchema_Interchange_Directive object. |
|
70 | + */ |
|
71 | + public function validateDirective($d) { |
|
72 | + $id = $d->id->toString(); |
|
73 | + $this->context[] = "directive '$id'"; |
|
74 | + $this->validateId($d->id); |
|
75 | + |
|
76 | + $this->with($d, 'description') |
|
77 | + ->assertNotEmpty(); |
|
78 | + |
|
79 | + // BEGIN - handled by InterchangeBuilder |
|
80 | + $this->with($d, 'type') |
|
81 | + ->assertNotEmpty(); |
|
82 | + $this->with($d, 'typeAllowsNull') |
|
83 | + ->assertIsBool(); |
|
84 | + try { |
|
85 | + // This also tests validity of $d->type |
|
86 | + $this->parser->parse($d->default, $d->type, $d->typeAllowsNull); |
|
87 | + } catch (HTMLPurifier_VarParserException $e) { |
|
88 | + $this->error('default', 'had error: ' . $e->getMessage()); |
|
89 | + } |
|
90 | + // END - handled by InterchangeBuilder |
|
91 | + |
|
92 | + if (!is_null($d->allowed) || !empty($d->valueAliases)) { |
|
93 | + // allowed and valueAliases require that we be dealing with |
|
94 | + // strings, so check for that early. |
|
95 | + $d_int = HTMLPurifier_VarParser::$types[$d->type]; |
|
96 | + if (!isset(HTMLPurifier_VarParser::$stringTypes[$d_int])) { |
|
97 | + $this->error('type', 'must be a string type when used with allowed or value aliases'); |
|
98 | + } |
|
99 | + } |
|
100 | + |
|
101 | + $this->validateDirectiveAllowed($d); |
|
102 | + $this->validateDirectiveValueAliases($d); |
|
103 | + $this->validateDirectiveAliases($d); |
|
104 | + |
|
105 | + array_pop($this->context); |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Extra validation if $allowed member variable of |
|
110 | + * HTMLPurifier_ConfigSchema_Interchange_Directive is defined. |
|
111 | + */ |
|
112 | + public function validateDirectiveAllowed($d) { |
|
113 | + if (is_null($d->allowed)) return; |
|
114 | + $this->with($d, 'allowed') |
|
115 | + ->assertNotEmpty() |
|
116 | + ->assertIsLookup(); // handled by InterchangeBuilder |
|
117 | + if (is_string($d->default) && !isset($d->allowed[$d->default])) { |
|
118 | + $this->error('default', 'must be an allowed value'); |
|
119 | + } |
|
120 | + $this->context[] = 'allowed'; |
|
121 | + foreach ($d->allowed as $val => $x) { |
|
122 | + if (!is_string($val)) $this->error("value $val", 'must be a string'); |
|
123 | + } |
|
124 | + array_pop($this->context); |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Extra validation if $valueAliases member variable of |
|
129 | + * HTMLPurifier_ConfigSchema_Interchange_Directive is defined. |
|
130 | + */ |
|
131 | + public function validateDirectiveValueAliases($d) { |
|
132 | + if (is_null($d->valueAliases)) return; |
|
133 | + $this->with($d, 'valueAliases') |
|
134 | + ->assertIsArray(); // handled by InterchangeBuilder |
|
135 | + $this->context[] = 'valueAliases'; |
|
136 | + foreach ($d->valueAliases as $alias => $real) { |
|
137 | + if (!is_string($alias)) $this->error("alias $alias", 'must be a string'); |
|
138 | + if (!is_string($real)) $this->error("alias target $real from alias '$alias'", 'must be a string'); |
|
139 | + if ($alias === $real) { |
|
140 | + $this->error("alias '$alias'", "must not be an alias to itself"); |
|
141 | + } |
|
142 | + } |
|
143 | + if (!is_null($d->allowed)) { |
|
144 | + foreach ($d->valueAliases as $alias => $real) { |
|
145 | + if (isset($d->allowed[$alias])) { |
|
146 | + $this->error("alias '$alias'", 'must not be an allowed value'); |
|
147 | + } elseif (!isset($d->allowed[$real])) { |
|
148 | + $this->error("alias '$alias'", 'must be an alias to an allowed value'); |
|
149 | + } |
|
150 | + } |
|
151 | + } |
|
152 | + array_pop($this->context); |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Extra validation if $aliases member variable of |
|
157 | + * HTMLPurifier_ConfigSchema_Interchange_Directive is defined. |
|
158 | + */ |
|
159 | + public function validateDirectiveAliases($d) { |
|
160 | + $this->with($d, 'aliases') |
|
161 | + ->assertIsArray(); // handled by InterchangeBuilder |
|
162 | + $this->context[] = 'aliases'; |
|
163 | + foreach ($d->aliases as $alias) { |
|
164 | + $this->validateId($alias); |
|
165 | + $s = $alias->toString(); |
|
166 | + if (isset($this->interchange->directives[$s])) { |
|
167 | + $this->error("alias '$s'", 'collides with another directive'); |
|
168 | + } |
|
169 | + if (isset($this->aliases[$s])) { |
|
170 | + $other_directive = $this->aliases[$s]; |
|
171 | + $this->error("alias '$s'", "collides with alias for directive '$other_directive'"); |
|
172 | + } |
|
173 | + $this->aliases[$s] = $d->id->toString(); |
|
174 | + } |
|
175 | + array_pop($this->context); |
|
176 | + } |
|
177 | + |
|
178 | + // protected helper functions |
|
179 | + |
|
180 | + /** |
|
181 | + * Convenience function for generating HTMLPurifier_ConfigSchema_ValidatorAtom |
|
182 | + * for validating simple member variables of objects. |
|
183 | + */ |
|
184 | + protected function with($obj, $member) { |
|
185 | + return new HTMLPurifier_ConfigSchema_ValidatorAtom($this->getFormattedContext(), $obj, $member); |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Emits an error, providing helpful context. |
|
190 | + */ |
|
191 | + protected function error($target, $msg) { |
|
192 | + if ($target !== false) $prefix = ucfirst($target) . ' in ' . $this->getFormattedContext(); |
|
193 | + else $prefix = ucfirst($this->getFormattedContext()); |
|
194 | + throw new HTMLPurifier_ConfigSchema_Exception(trim($prefix . ' ' . $msg)); |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * Returns a formatted context string. |
|
199 | + */ |
|
200 | + protected function getFormattedContext() { |
|
201 | + return implode(' in ', array_reverse($this->context)); |
|
202 | + } |
|
203 | 203 | |
204 | 204 | } |
205 | 205 |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | $this->context[] = 'valueAliases'; |
136 | 136 | foreach ($d->valueAliases as $alias => $real) { |
137 | 137 | if (!is_string($alias)) $this->error("alias $alias", 'must be a string'); |
138 | - if (!is_string($real)) $this->error("alias target $real from alias '$alias'", 'must be a string'); |
|
138 | + if (!is_string($real)) $this->error("alias target $real from alias '$alias'", 'must be a string'); |
|
139 | 139 | if ($alias === $real) { |
140 | 140 | $this->error("alias '$alias'", "must not be an alias to itself"); |
141 | 141 | } |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | * Emits an error, providing helpful context. |
190 | 190 | */ |
191 | 191 | protected function error($target, $msg) { |
192 | - if ($target !== false) $prefix = ucfirst($target) . ' in ' . $this->getFormattedContext(); |
|
192 | + if ($target !== false) $prefix = ucfirst($target) . ' in ' . $this->getFormattedContext(); |
|
193 | 193 | else $prefix = ucfirst($this->getFormattedContext()); |
194 | 194 | throw new HTMLPurifier_ConfigSchema_Exception(trim($prefix . ' ' . $msg)); |
195 | 195 | } |
@@ -41,7 +41,9 @@ discard block |
||
41 | 41 | // arrays, so we don't use the identical !== comparison |
42 | 42 | foreach ($interchange->directives as $i => $directive) { |
43 | 43 | $id = $directive->id->toString(); |
44 | - if ($i != $id) $this->error(false, "Integrity violation: key '$i' does not match internal id '$id'"); |
|
44 | + if ($i != $id) { |
|
45 | + $this->error(false, "Integrity violation: key '$i' does not match internal id '$id'"); |
|
46 | + } |
|
45 | 47 | $this->validateDirective($directive); |
46 | 48 | } |
47 | 49 | return true; |
@@ -110,7 +112,9 @@ discard block |
||
110 | 112 | * HTMLPurifier_ConfigSchema_Interchange_Directive is defined. |
111 | 113 | */ |
112 | 114 | public function validateDirectiveAllowed($d) { |
113 | - if (is_null($d->allowed)) return; |
|
115 | + if (is_null($d->allowed)) { |
|
116 | + return; |
|
117 | + } |
|
114 | 118 | $this->with($d, 'allowed') |
115 | 119 | ->assertNotEmpty() |
116 | 120 | ->assertIsLookup(); // handled by InterchangeBuilder |
@@ -119,7 +123,9 @@ discard block |
||
119 | 123 | } |
120 | 124 | $this->context[] = 'allowed'; |
121 | 125 | foreach ($d->allowed as $val => $x) { |
122 | - if (!is_string($val)) $this->error("value $val", 'must be a string'); |
|
126 | + if (!is_string($val)) { |
|
127 | + $this->error("value $val", 'must be a string'); |
|
128 | + } |
|
123 | 129 | } |
124 | 130 | array_pop($this->context); |
125 | 131 | } |
@@ -129,13 +135,19 @@ discard block |
||
129 | 135 | * HTMLPurifier_ConfigSchema_Interchange_Directive is defined. |
130 | 136 | */ |
131 | 137 | public function validateDirectiveValueAliases($d) { |
132 | - if (is_null($d->valueAliases)) return; |
|
138 | + if (is_null($d->valueAliases)) { |
|
139 | + return; |
|
140 | + } |
|
133 | 141 | $this->with($d, 'valueAliases') |
134 | 142 | ->assertIsArray(); // handled by InterchangeBuilder |
135 | 143 | $this->context[] = 'valueAliases'; |
136 | 144 | foreach ($d->valueAliases as $alias => $real) { |
137 | - if (!is_string($alias)) $this->error("alias $alias", 'must be a string'); |
|
138 | - if (!is_string($real)) $this->error("alias target $real from alias '$alias'", 'must be a string'); |
|
145 | + if (!is_string($alias)) { |
|
146 | + $this->error("alias $alias", 'must be a string'); |
|
147 | + } |
|
148 | + if (!is_string($real)) { |
|
149 | + $this->error("alias target $real from alias '$alias'", 'must be a string'); |
|
150 | + } |
|
139 | 151 | if ($alias === $real) { |
140 | 152 | $this->error("alias '$alias'", "must not be an alias to itself"); |
141 | 153 | } |
@@ -189,8 +201,11 @@ discard block |
||
189 | 201 | * Emits an error, providing helpful context. |
190 | 202 | */ |
191 | 203 | protected function error($target, $msg) { |
192 | - if ($target !== false) $prefix = ucfirst($target) . ' in ' . $this->getFormattedContext(); |
|
193 | - else $prefix = ucfirst($this->getFormattedContext()); |
|
204 | + if ($target !== false) { |
|
205 | + $prefix = ucfirst($target) . ' in ' . $this->getFormattedContext(); |
|
206 | + } else { |
|
207 | + $prefix = ucfirst($this->getFormattedContext()); |
|
208 | + } |
|
194 | 209 | throw new HTMLPurifier_ConfigSchema_Exception(trim($prefix . ' ' . $msg)); |
195 | 210 | } |
196 | 211 |
@@ -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 |
@@ -15,7 +15,7 @@ |
||
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() { |
@@ -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 | } |
@@ -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 |
@@ -105,7 +105,7 @@ |
||
105 | 105 | $value = $def->content_model; |
106 | 106 | if (is_object($value)) { |
107 | 107 | trigger_error( |
108 | - 'Literal object child definitions should be stored in '. |
|
108 | + 'Literal object child definitions should be stored in ' . |
|
109 | 109 | 'ElementDef->child not ElementDef->content_model', |
110 | 110 | E_USER_NOTICE |
111 | 111 | ); |
@@ -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', |
@@ -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 |
@@ -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 | } |