@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | */ |
68 | 68 | public function __construct($data = null, $readOnly = false) |
69 | 69 | { |
70 | - if($data !== null) |
|
70 | + if ($data !== null) |
|
71 | 71 | $this->copyFrom($data); |
72 | 72 | $this->setReadOnly($readOnly); |
73 | 73 | } |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | */ |
126 | 126 | public function itemAt($index) |
127 | 127 | { |
128 | - if($index >= 0 && $index < $this->_c) |
|
128 | + if ($index >= 0 && $index < $this->_c) |
|
129 | 129 | return $this->_d[$index]; |
130 | 130 | else |
131 | 131 | throw new TInvalidDataValueException('list_index_invalid', $index); |
@@ -154,11 +154,11 @@ discard block |
||
154 | 154 | */ |
155 | 155 | public function insertAt($index, $item) |
156 | 156 | { |
157 | - if(!$this->_r) |
|
157 | + if (!$this->_r) |
|
158 | 158 | { |
159 | - if($index === $this->_c) |
|
159 | + if ($index === $this->_c) |
|
160 | 160 | $this->_d[$this->_c++] = $item; |
161 | - elseif($index >= 0 && $index < $this->_c) |
|
161 | + elseif ($index >= 0 && $index < $this->_c) |
|
162 | 162 | { |
163 | 163 | array_splice($this->_d, $index, 0, [$item]); |
164 | 164 | $this->_c++; |
@@ -181,9 +181,9 @@ discard block |
||
181 | 181 | */ |
182 | 182 | public function remove($item) |
183 | 183 | { |
184 | - if(!$this->_r) |
|
184 | + if (!$this->_r) |
|
185 | 185 | { |
186 | - if(($index = $this->indexOf($item)) >= 0) |
|
186 | + if (($index = $this->indexOf($item)) >= 0) |
|
187 | 187 | { |
188 | 188 | $this->removeAt($index); |
189 | 189 | return $index; |
@@ -204,12 +204,12 @@ discard block |
||
204 | 204 | */ |
205 | 205 | public function removeAt($index) |
206 | 206 | { |
207 | - if(!$this->_r) |
|
207 | + if (!$this->_r) |
|
208 | 208 | { |
209 | - if($index >= 0 && $index < $this->_c) |
|
209 | + if ($index >= 0 && $index < $this->_c) |
|
210 | 210 | { |
211 | 211 | $this->_c--; |
212 | - if($index === $this->_c) |
|
212 | + if ($index === $this->_c) |
|
213 | 213 | return array_pop($this->_d); |
214 | 214 | else |
215 | 215 | { |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | */ |
232 | 232 | public function clear() |
233 | 233 | { |
234 | - for($i = $this->_c - 1;$i >= 0;--$i) |
|
234 | + for ($i = $this->_c - 1; $i >= 0; --$i) |
|
235 | 235 | $this->removeAt($i); |
236 | 236 | } |
237 | 237 | |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | */ |
251 | 251 | public function indexOf($item) |
252 | 252 | { |
253 | - if(($index = array_search($item, $this->_d, true)) === false) |
|
253 | + if (($index = array_search($item, $this->_d, true)) === false) |
|
254 | 254 | return -1; |
255 | 255 | else |
256 | 256 | return $index; |
@@ -267,9 +267,9 @@ discard block |
||
267 | 267 | */ |
268 | 268 | public function insertBefore($baseitem, $item) |
269 | 269 | { |
270 | - if(!$this->_r) |
|
270 | + if (!$this->_r) |
|
271 | 271 | { |
272 | - if(($index = $this->indexOf($baseitem)) == -1) |
|
272 | + if (($index = $this->indexOf($baseitem)) == -1) |
|
273 | 273 | throw new TInvalidDataValueException('list_item_inexistent'); |
274 | 274 | |
275 | 275 | $this->insertAt($index, $item); |
@@ -291,9 +291,9 @@ discard block |
||
291 | 291 | */ |
292 | 292 | public function insertAfter($baseitem, $item) |
293 | 293 | { |
294 | - if(!$this->_r) |
|
294 | + if (!$this->_r) |
|
295 | 295 | { |
296 | - if(($index = $this->indexOf($baseitem)) == -1) |
|
296 | + if (($index = $this->indexOf($baseitem)) == -1) |
|
297 | 297 | throw new TInvalidDataValueException('list_item_inexistent'); |
298 | 298 | |
299 | 299 | $this->insertAt($index + 1, $item); |
@@ -320,14 +320,14 @@ discard block |
||
320 | 320 | */ |
321 | 321 | public function copyFrom($data) |
322 | 322 | { |
323 | - if(is_array($data) || ($data instanceof \Traversable)) |
|
323 | + if (is_array($data) || ($data instanceof \Traversable)) |
|
324 | 324 | { |
325 | - if($this->_c > 0) |
|
325 | + if ($this->_c > 0) |
|
326 | 326 | $this->clear(); |
327 | - foreach($data as $item) |
|
327 | + foreach ($data as $item) |
|
328 | 328 | $this->add($item); |
329 | 329 | } |
330 | - elseif($data !== null) |
|
330 | + elseif ($data !== null) |
|
331 | 331 | throw new TInvalidDataTypeException('list_data_not_iterable'); |
332 | 332 | } |
333 | 333 | |
@@ -339,12 +339,12 @@ discard block |
||
339 | 339 | */ |
340 | 340 | public function mergeWith($data) |
341 | 341 | { |
342 | - if(is_array($data) || ($data instanceof \Traversable)) |
|
342 | + if (is_array($data) || ($data instanceof \Traversable)) |
|
343 | 343 | { |
344 | - foreach($data as $item) |
|
344 | + foreach ($data as $item) |
|
345 | 345 | $this->add($item); |
346 | 346 | } |
347 | - elseif($data !== null) |
|
347 | + elseif ($data !== null) |
|
348 | 348 | throw new TInvalidDataTypeException('list_data_not_iterable'); |
349 | 349 | } |
350 | 350 | |
@@ -379,7 +379,7 @@ discard block |
||
379 | 379 | */ |
380 | 380 | public function offsetSet($offset, $item) |
381 | 381 | { |
382 | - if($offset === null || $offset === $this->_c) |
|
382 | + if ($offset === null || $offset === $this->_c) |
|
383 | 383 | $this->insertAt($this->_c, $item); |
384 | 384 | else |
385 | 385 | { |
@@ -67,8 +67,9 @@ discard block |
||
67 | 67 | */ |
68 | 68 | public function __construct($data = null, $readOnly = false) |
69 | 69 | { |
70 | - if($data !== null) |
|
71 | - $this->copyFrom($data); |
|
70 | + if($data !== null) { |
|
71 | + $this->copyFrom($data); |
|
72 | + } |
|
72 | 73 | $this->setReadOnly($readOnly); |
73 | 74 | } |
74 | 75 | |
@@ -125,10 +126,11 @@ discard block |
||
125 | 126 | */ |
126 | 127 | public function itemAt($index) |
127 | 128 | { |
128 | - if($index >= 0 && $index < $this->_c) |
|
129 | - return $this->_d[$index]; |
|
130 | - else |
|
131 | - throw new TInvalidDataValueException('list_index_invalid', $index); |
|
129 | + if($index >= 0 && $index < $this->_c) { |
|
130 | + return $this->_d[$index]; |
|
131 | + } else { |
|
132 | + throw new TInvalidDataValueException('list_index_invalid', $index); |
|
133 | + } |
|
132 | 134 | } |
133 | 135 | |
134 | 136 | /** |
@@ -156,18 +158,18 @@ discard block |
||
156 | 158 | { |
157 | 159 | if(!$this->_r) |
158 | 160 | { |
159 | - if($index === $this->_c) |
|
160 | - $this->_d[$this->_c++] = $item; |
|
161 | - elseif($index >= 0 && $index < $this->_c) |
|
161 | + if($index === $this->_c) { |
|
162 | + $this->_d[$this->_c++] = $item; |
|
163 | + } elseif($index >= 0 && $index < $this->_c) |
|
162 | 164 | { |
163 | 165 | array_splice($this->_d, $index, 0, [$item]); |
164 | 166 | $this->_c++; |
167 | + } else { |
|
168 | + throw new TInvalidDataValueException('list_index_invalid', $index); |
|
165 | 169 | } |
166 | - else |
|
167 | - throw new TInvalidDataValueException('list_index_invalid', $index); |
|
170 | + } else { |
|
171 | + throw new TInvalidOperationException('list_readonly', get_class($this)); |
|
168 | 172 | } |
169 | - else |
|
170 | - throw new TInvalidOperationException('list_readonly', get_class($this)); |
|
171 | 173 | } |
172 | 174 | |
173 | 175 | /** |
@@ -187,12 +189,12 @@ discard block |
||
187 | 189 | { |
188 | 190 | $this->removeAt($index); |
189 | 191 | return $index; |
192 | + } else { |
|
193 | + throw new TInvalidDataValueException('list_item_inexistent'); |
|
190 | 194 | } |
191 | - else |
|
192 | - throw new TInvalidDataValueException('list_item_inexistent'); |
|
195 | + } else { |
|
196 | + throw new TInvalidOperationException('list_readonly', get_class($this)); |
|
193 | 197 | } |
194 | - else |
|
195 | - throw new TInvalidOperationException('list_readonly', get_class($this)); |
|
196 | 198 | } |
197 | 199 | |
198 | 200 | /** |
@@ -209,20 +211,20 @@ discard block |
||
209 | 211 | if($index >= 0 && $index < $this->_c) |
210 | 212 | { |
211 | 213 | $this->_c--; |
212 | - if($index === $this->_c) |
|
213 | - return array_pop($this->_d); |
|
214 | - else |
|
214 | + if($index === $this->_c) { |
|
215 | + return array_pop($this->_d); |
|
216 | + } else |
|
215 | 217 | { |
216 | 218 | $item = $this->_d[$index]; |
217 | 219 | array_splice($this->_d, $index, 1); |
218 | 220 | return $item; |
219 | 221 | } |
222 | + } else { |
|
223 | + throw new TInvalidDataValueException('list_index_invalid', $index); |
|
220 | 224 | } |
221 | - else |
|
222 | - throw new TInvalidDataValueException('list_index_invalid', $index); |
|
225 | + } else { |
|
226 | + throw new TInvalidOperationException('list_readonly', get_class($this)); |
|
223 | 227 | } |
224 | - else |
|
225 | - throw new TInvalidOperationException('list_readonly', get_class($this)); |
|
226 | 228 | } |
227 | 229 | |
228 | 230 | /** |
@@ -231,8 +233,9 @@ discard block |
||
231 | 233 | */ |
232 | 234 | public function clear() |
233 | 235 | { |
234 | - for($i = $this->_c - 1;$i >= 0;--$i) |
|
235 | - $this->removeAt($i); |
|
236 | + for($i = $this->_c - 1;$i >= 0;--$i) { |
|
237 | + $this->removeAt($i); |
|
238 | + } |
|
236 | 239 | } |
237 | 240 | |
238 | 241 | /** |
@@ -250,10 +253,11 @@ discard block |
||
250 | 253 | */ |
251 | 254 | public function indexOf($item) |
252 | 255 | { |
253 | - if(($index = array_search($item, $this->_d, true)) === false) |
|
254 | - return -1; |
|
255 | - else |
|
256 | - return $index; |
|
256 | + if(($index = array_search($item, $this->_d, true)) === false) { |
|
257 | + return -1; |
|
258 | + } else { |
|
259 | + return $index; |
|
260 | + } |
|
257 | 261 | } |
258 | 262 | |
259 | 263 | /** |
@@ -269,15 +273,16 @@ discard block |
||
269 | 273 | { |
270 | 274 | if(!$this->_r) |
271 | 275 | { |
272 | - if(($index = $this->indexOf($baseitem)) == -1) |
|
273 | - throw new TInvalidDataValueException('list_item_inexistent'); |
|
276 | + if(($index = $this->indexOf($baseitem)) == -1) { |
|
277 | + throw new TInvalidDataValueException('list_item_inexistent'); |
|
278 | + } |
|
274 | 279 | |
275 | 280 | $this->insertAt($index, $item); |
276 | 281 | |
277 | 282 | return $index; |
283 | + } else { |
|
284 | + throw new TInvalidOperationException('list_readonly', get_class($this)); |
|
278 | 285 | } |
279 | - else |
|
280 | - throw new TInvalidOperationException('list_readonly', get_class($this)); |
|
281 | 286 | } |
282 | 287 | |
283 | 288 | /** |
@@ -293,15 +298,16 @@ discard block |
||
293 | 298 | { |
294 | 299 | if(!$this->_r) |
295 | 300 | { |
296 | - if(($index = $this->indexOf($baseitem)) == -1) |
|
297 | - throw new TInvalidDataValueException('list_item_inexistent'); |
|
301 | + if(($index = $this->indexOf($baseitem)) == -1) { |
|
302 | + throw new TInvalidDataValueException('list_item_inexistent'); |
|
303 | + } |
|
298 | 304 | |
299 | 305 | $this->insertAt($index + 1, $item); |
300 | 306 | |
301 | 307 | return $index + 1; |
308 | + } else { |
|
309 | + throw new TInvalidOperationException('list_readonly', get_class($this)); |
|
302 | 310 | } |
303 | - else |
|
304 | - throw new TInvalidOperationException('list_readonly', get_class($this)); |
|
305 | 311 | } |
306 | 312 | |
307 | 313 | /** |
@@ -322,13 +328,15 @@ discard block |
||
322 | 328 | { |
323 | 329 | if(is_array($data) || ($data instanceof \Traversable)) |
324 | 330 | { |
325 | - if($this->_c > 0) |
|
326 | - $this->clear(); |
|
327 | - foreach($data as $item) |
|
328 | - $this->add($item); |
|
331 | + if($this->_c > 0) { |
|
332 | + $this->clear(); |
|
333 | + } |
|
334 | + foreach($data as $item) { |
|
335 | + $this->add($item); |
|
336 | + } |
|
337 | + } elseif($data !== null) { |
|
338 | + throw new TInvalidDataTypeException('list_data_not_iterable'); |
|
329 | 339 | } |
330 | - elseif($data !== null) |
|
331 | - throw new TInvalidDataTypeException('list_data_not_iterable'); |
|
332 | 340 | } |
333 | 341 | |
334 | 342 | /** |
@@ -341,11 +349,12 @@ discard block |
||
341 | 349 | { |
342 | 350 | if(is_array($data) || ($data instanceof \Traversable)) |
343 | 351 | { |
344 | - foreach($data as $item) |
|
345 | - $this->add($item); |
|
352 | + foreach($data as $item) { |
|
353 | + $this->add($item); |
|
354 | + } |
|
355 | + } elseif($data !== null) { |
|
356 | + throw new TInvalidDataTypeException('list_data_not_iterable'); |
|
346 | 357 | } |
347 | - elseif($data !== null) |
|
348 | - throw new TInvalidDataTypeException('list_data_not_iterable'); |
|
349 | 358 | } |
350 | 359 | |
351 | 360 | /** |
@@ -379,9 +388,9 @@ discard block |
||
379 | 388 | */ |
380 | 389 | public function offsetSet($offset, $item) |
381 | 390 | { |
382 | - if($offset === null || $offset === $this->_c) |
|
383 | - $this->insertAt($this->_c, $item); |
|
384 | - else |
|
391 | + if($offset === null || $offset === $this->_c) { |
|
392 | + $this->insertAt($this->_c, $item); |
|
393 | + } else |
|
385 | 394 | { |
386 | 395 | $this->removeAt($offset); |
387 | 396 | $this->insertAt($offset, $item); |
@@ -57,10 +57,10 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function insertAt($index, $item) |
59 | 59 | { |
60 | - if($item instanceof TXmlElement) |
|
60 | + if ($item instanceof TXmlElement) |
|
61 | 61 | { |
62 | 62 | parent::insertAt($index, $item); |
63 | - if($item->getParent() !== null) |
|
63 | + if ($item->getParent() !== null) |
|
64 | 64 | $item->getParent()->getElements()->remove($item); |
65 | 65 | $item->setParent($this->_o); |
66 | 66 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | public function removeAt($index) |
79 | 79 | { |
80 | 80 | $item = parent::removeAt($index); |
81 | - if($item instanceof TXmlElement) |
|
81 | + if ($item instanceof TXmlElement) |
|
82 | 82 | $item->setParent(null); |
83 | 83 | return $item; |
84 | 84 | } |
@@ -60,12 +60,13 @@ discard block |
||
60 | 60 | if($item instanceof TXmlElement) |
61 | 61 | { |
62 | 62 | parent::insertAt($index, $item); |
63 | - if($item->getParent() !== null) |
|
64 | - $item->getParent()->getElements()->remove($item); |
|
63 | + if($item->getParent() !== null) { |
|
64 | + $item->getParent()->getElements()->remove($item); |
|
65 | + } |
|
65 | 66 | $item->setParent($this->_o); |
67 | + } else { |
|
68 | + throw new TInvalidDataTypeException('xmlelementlist_xmlelement_required'); |
|
66 | 69 | } |
67 | - else |
|
68 | - throw new TInvalidDataTypeException('xmlelementlist_xmlelement_required'); |
|
69 | 70 | } |
70 | 71 | |
71 | 72 | /** |
@@ -78,8 +79,9 @@ discard block |
||
78 | 79 | public function removeAt($index) |
79 | 80 | { |
80 | 81 | $item = parent::removeAt($index); |
81 | - if($item instanceof TXmlElement) |
|
82 | - $item->setParent(null); |
|
82 | + if($item instanceof TXmlElement) { |
|
83 | + $item->setParent(null); |
|
84 | + } |
|
83 | 85 | return $item; |
84 | 86 | } |
85 | 87 | } |
86 | 88 | \ No newline at end of file |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | */ |
126 | 126 | public function loadFromFile($file) |
127 | 127 | { |
128 | - if(($str = @file_get_contents($file)) !== false) |
|
128 | + if (($str = @file_get_contents($file)) !== false) |
|
129 | 129 | return $this->loadFromString($str); |
130 | 130 | else |
131 | 131 | throw new TIOException('xmldocument_file_read_failed', $file); |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | { |
142 | 142 | // TODO: since PHP 5.1, we can get parsing errors and throw them as exception |
143 | 143 | $doc = new \DOMDocument(); |
144 | - if($doc->loadXML($string) === false) |
|
144 | + if ($doc->loadXML($string) === false) |
|
145 | 145 | return false; |
146 | 146 | |
147 | 147 | $this->setEncoding($doc->encoding); |
@@ -156,28 +156,28 @@ discard block |
||
156 | 156 | $attributes->clear(); |
157 | 157 | |
158 | 158 | static $bSimpleXml; |
159 | - if($bSimpleXml === null) |
|
160 | - $bSimpleXml = (boolean)function_exists('simplexml_load_string'); |
|
159 | + if ($bSimpleXml === null) |
|
160 | + $bSimpleXml = (boolean) function_exists('simplexml_load_string'); |
|
161 | 161 | |
162 | - if($bSimpleXml) |
|
162 | + if ($bSimpleXml) |
|
163 | 163 | { |
164 | 164 | $simpleDoc = simplexml_load_string($string); |
165 | 165 | $docNamespaces = $simpleDoc->getDocNamespaces(false); |
166 | 166 | $simpleDoc = null; |
167 | - foreach($docNamespaces as $prefix => $uri) |
|
167 | + foreach ($docNamespaces as $prefix => $uri) |
|
168 | 168 | { |
169 | - if($prefix === '') |
|
169 | + if ($prefix === '') |
|
170 | 170 | $attributes->add('xmlns', $uri); |
171 | 171 | else |
172 | - $attributes->add('xmlns:' . $prefix, $uri); |
|
172 | + $attributes->add('xmlns:'.$prefix, $uri); |
|
173 | 173 | } |
174 | 174 | } |
175 | 175 | |
176 | - foreach($element->attributes as $name => $attr) |
|
177 | - $attributes->add(($attr->prefix === '' ? '' : $attr->prefix . ':') . $name, $attr->value); |
|
178 | - foreach($element->childNodes as $child) |
|
176 | + foreach ($element->attributes as $name => $attr) |
|
177 | + $attributes->add(($attr->prefix === '' ? '' : $attr->prefix.':').$name, $attr->value); |
|
178 | + foreach ($element->childNodes as $child) |
|
179 | 179 | { |
180 | - if($child instanceof \DOMElement) |
|
180 | + if ($child instanceof \DOMElement) |
|
181 | 181 | $elements->add($this->buildElement($child)); |
182 | 182 | } |
183 | 183 | |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | */ |
192 | 192 | public function saveToFile($file) |
193 | 193 | { |
194 | - if(($fw = fopen($file, 'w')) !== false) |
|
194 | + if (($fw = fopen($file, 'w')) !== false) |
|
195 | 195 | { |
196 | 196 | fwrite($fw, $this->saveToString()); |
197 | 197 | fclose($fw); |
@@ -206,9 +206,9 @@ discard block |
||
206 | 206 | */ |
207 | 207 | public function saveToString() |
208 | 208 | { |
209 | - $version = empty($this->_version)?' version="1.0"':' version="' . $this->_version . '"'; |
|
210 | - $encoding = empty($this->_encoding)?'':' encoding="' . $this->_encoding . '"'; |
|
211 | - return "<?xml{$version}{$encoding}?>\n" . $this->toString(0); |
|
209 | + $version = empty($this->_version) ? ' version="1.0"' : ' version="'.$this->_version.'"'; |
|
210 | + $encoding = empty($this->_encoding) ? '' : ' encoding="'.$this->_encoding.'"'; |
|
211 | + return "<?xml{$version}{$encoding}?>\n".$this->toString(0); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
@@ -240,12 +240,12 @@ discard block |
||
240 | 240 | { |
241 | 241 | $element = new TXmlElement($node->tagName); |
242 | 242 | $element->setValue($node->nodeValue); |
243 | - foreach($node->attributes as $name => $attr) |
|
244 | - $element->getAttributes()->add(($attr->prefix === '' ? '' : $attr->prefix . ':') . $name, $attr->value); |
|
243 | + foreach ($node->attributes as $name => $attr) |
|
244 | + $element->getAttributes()->add(($attr->prefix === '' ? '' : $attr->prefix.':').$name, $attr->value); |
|
245 | 245 | |
246 | - foreach($node->childNodes as $child) |
|
246 | + foreach ($node->childNodes as $child) |
|
247 | 247 | { |
248 | - if($child instanceof \DOMElement) |
|
248 | + if ($child instanceof \DOMElement) |
|
249 | 249 | $element->getElements()->add($this->buildElement($child)); |
250 | 250 | } |
251 | 251 | return $element; |
@@ -125,10 +125,11 @@ discard block |
||
125 | 125 | */ |
126 | 126 | public function loadFromFile($file) |
127 | 127 | { |
128 | - if(($str = @file_get_contents($file)) !== false) |
|
129 | - return $this->loadFromString($str); |
|
130 | - else |
|
131 | - throw new TIOException('xmldocument_file_read_failed', $file); |
|
128 | + if(($str = @file_get_contents($file)) !== false) { |
|
129 | + return $this->loadFromString($str); |
|
130 | + } else { |
|
131 | + throw new TIOException('xmldocument_file_read_failed', $file); |
|
132 | + } |
|
132 | 133 | } |
133 | 134 | |
134 | 135 | /** |
@@ -141,8 +142,9 @@ discard block |
||
141 | 142 | { |
142 | 143 | // TODO: since PHP 5.1, we can get parsing errors and throw them as exception |
143 | 144 | $doc = new \DOMDocument(); |
144 | - if($doc->loadXML($string) === false) |
|
145 | - return false; |
|
145 | + if($doc->loadXML($string) === false) { |
|
146 | + return false; |
|
147 | + } |
|
146 | 148 | |
147 | 149 | $this->setEncoding($doc->encoding); |
148 | 150 | $this->setVersion($doc->xmlVersion); |
@@ -156,8 +158,9 @@ discard block |
||
156 | 158 | $attributes->clear(); |
157 | 159 | |
158 | 160 | static $bSimpleXml; |
159 | - if($bSimpleXml === null) |
|
160 | - $bSimpleXml = (boolean)function_exists('simplexml_load_string'); |
|
161 | + if($bSimpleXml === null) { |
|
162 | + $bSimpleXml = (boolean)function_exists('simplexml_load_string'); |
|
163 | + } |
|
161 | 164 | |
162 | 165 | if($bSimpleXml) |
163 | 166 | { |
@@ -166,19 +169,22 @@ discard block |
||
166 | 169 | $simpleDoc = null; |
167 | 170 | foreach($docNamespaces as $prefix => $uri) |
168 | 171 | { |
169 | - if($prefix === '') |
|
170 | - $attributes->add('xmlns', $uri); |
|
171 | - else |
|
172 | - $attributes->add('xmlns:' . $prefix, $uri); |
|
172 | + if($prefix === '') { |
|
173 | + $attributes->add('xmlns', $uri); |
|
174 | + } else { |
|
175 | + $attributes->add('xmlns:' . $prefix, $uri); |
|
176 | + } |
|
173 | 177 | } |
174 | 178 | } |
175 | 179 | |
176 | - foreach($element->attributes as $name => $attr) |
|
177 | - $attributes->add(($attr->prefix === '' ? '' : $attr->prefix . ':') . $name, $attr->value); |
|
180 | + foreach($element->attributes as $name => $attr) { |
|
181 | + $attributes->add(($attr->prefix === '' ? '' : $attr->prefix . ':') . $name, $attr->value); |
|
182 | + } |
|
178 | 183 | foreach($element->childNodes as $child) |
179 | 184 | { |
180 | - if($child instanceof \DOMElement) |
|
181 | - $elements->add($this->buildElement($child)); |
|
185 | + if($child instanceof \DOMElement) { |
|
186 | + $elements->add($this->buildElement($child)); |
|
187 | + } |
|
182 | 188 | } |
183 | 189 | |
184 | 190 | return true; |
@@ -195,9 +201,9 @@ discard block |
||
195 | 201 | { |
196 | 202 | fwrite($fw, $this->saveToString()); |
197 | 203 | fclose($fw); |
204 | + } else { |
|
205 | + throw new TIOException('xmldocument_file_write_failed', $file); |
|
198 | 206 | } |
199 | - else |
|
200 | - throw new TIOException('xmldocument_file_write_failed', $file); |
|
201 | 207 | } |
202 | 208 | |
203 | 209 | /** |
@@ -240,13 +246,15 @@ discard block |
||
240 | 246 | { |
241 | 247 | $element = new TXmlElement($node->tagName); |
242 | 248 | $element->setValue($node->nodeValue); |
243 | - foreach($node->attributes as $name => $attr) |
|
244 | - $element->getAttributes()->add(($attr->prefix === '' ? '' : $attr->prefix . ':') . $name, $attr->value); |
|
249 | + foreach($node->attributes as $name => $attr) { |
|
250 | + $element->getAttributes()->add(($attr->prefix === '' ? '' : $attr->prefix . ':') . $name, $attr->value); |
|
251 | + } |
|
245 | 252 | |
246 | 253 | foreach($node->childNodes as $child) |
247 | 254 | { |
248 | - if($child instanceof \DOMElement) |
|
249 | - $element->getElements()->add($this->buildElement($child)); |
|
255 | + if($child instanceof \DOMElement) { |
|
256 | + $element->getElements()->add($this->buildElement($child)); |
|
257 | + } |
|
250 | 258 | } |
251 | 259 | return $element; |
252 | 260 | } |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | */ |
132 | 132 | public function getAttribute($name) |
133 | 133 | { |
134 | - if($this->_attributes !== null) |
|
134 | + if ($this->_attributes !== null) |
|
135 | 135 | return $this->_attributes->itemAt($name); |
136 | 136 | else |
137 | 137 | return null; |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | */ |
152 | 152 | public function getElements() |
153 | 153 | { |
154 | - if(!$this->_elements) |
|
154 | + if (!$this->_elements) |
|
155 | 155 | $this->_elements = new TXmlElementList($this); |
156 | 156 | return $this->_elements; |
157 | 157 | } |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | */ |
162 | 162 | public function getAttributes() |
163 | 163 | { |
164 | - if(!$this->_attributes) |
|
164 | + if (!$this->_attributes) |
|
165 | 165 | $this->_attributes = new TMap; |
166 | 166 | return $this->_attributes; |
167 | 167 | } |
@@ -171,10 +171,10 @@ discard block |
||
171 | 171 | */ |
172 | 172 | public function getElementByTagName($tagName) |
173 | 173 | { |
174 | - if($this->_elements) |
|
174 | + if ($this->_elements) |
|
175 | 175 | { |
176 | - foreach($this->_elements as $element) |
|
177 | - if($element->_tagName === $tagName) |
|
176 | + foreach ($this->_elements as $element) |
|
177 | + if ($element->_tagName === $tagName) |
|
178 | 178 | return $element; |
179 | 179 | } |
180 | 180 | return null; |
@@ -186,10 +186,10 @@ discard block |
||
186 | 186 | public function getElementsByTagName($tagName) |
187 | 187 | { |
188 | 188 | $list = new TList; |
189 | - if($this->_elements) |
|
189 | + if ($this->_elements) |
|
190 | 190 | { |
191 | - foreach($this->_elements as $element) |
|
192 | - if($element->_tagName === $tagName) |
|
191 | + foreach ($this->_elements as $element) |
|
192 | + if ($element->_tagName === $tagName) |
|
193 | 193 | $list->add($element); |
194 | 194 | } |
195 | 195 | return $list; |
@@ -201,30 +201,30 @@ discard block |
||
201 | 201 | public function toString($indent = 0) |
202 | 202 | { |
203 | 203 | $attr = ''; |
204 | - if($this->_attributes !== null) |
|
204 | + if ($this->_attributes !== null) |
|
205 | 205 | { |
206 | - foreach($this->_attributes as $name => $value) |
|
206 | + foreach ($this->_attributes as $name => $value) |
|
207 | 207 | { |
208 | 208 | $value = $this->xmlEncode($value); |
209 | 209 | $attr .= " $name=\"$value\""; |
210 | 210 | } |
211 | 211 | } |
212 | 212 | $prefix = str_repeat(' ', $indent * 4); |
213 | - if($this->getHasElement()) |
|
213 | + if ($this->getHasElement()) |
|
214 | 214 | { |
215 | - $str = $prefix . "<{$this->_tagName}$attr>\n"; |
|
216 | - foreach($this->getElements() as $element) |
|
217 | - $str .= $element->toString($indent + 1) . "\n"; |
|
218 | - $str .= $prefix . "</{$this->_tagName}>"; |
|
215 | + $str = $prefix."<{$this->_tagName}$attr>\n"; |
|
216 | + foreach ($this->getElements() as $element) |
|
217 | + $str .= $element->toString($indent + 1)."\n"; |
|
218 | + $str .= $prefix."</{$this->_tagName}>"; |
|
219 | 219 | return $str; |
220 | 220 | } |
221 | - elseif(($value = $this->getValue()) !== '') |
|
221 | + elseif (($value = $this->getValue()) !== '') |
|
222 | 222 | { |
223 | 223 | $value = $this->xmlEncode($value); |
224 | - return $prefix . "<{$this->_tagName}$attr>$value</{$this->_tagName}>"; |
|
224 | + return $prefix."<{$this->_tagName}$attr>$value</{$this->_tagName}>"; |
|
225 | 225 | } |
226 | 226 | else |
227 | - return $prefix . "<{$this->_tagName}$attr />"; |
|
227 | + return $prefix."<{$this->_tagName}$attr />"; |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | /** |
@@ -131,10 +131,11 @@ discard block |
||
131 | 131 | */ |
132 | 132 | public function getAttribute($name) |
133 | 133 | { |
134 | - if($this->_attributes !== null) |
|
135 | - return $this->_attributes->itemAt($name); |
|
136 | - else |
|
137 | - return null; |
|
134 | + if($this->_attributes !== null) { |
|
135 | + return $this->_attributes->itemAt($name); |
|
136 | + } else { |
|
137 | + return null; |
|
138 | + } |
|
138 | 139 | } |
139 | 140 | |
140 | 141 | /** |
@@ -151,8 +152,9 @@ discard block |
||
151 | 152 | */ |
152 | 153 | public function getElements() |
153 | 154 | { |
154 | - if(!$this->_elements) |
|
155 | - $this->_elements = new TXmlElementList($this); |
|
155 | + if(!$this->_elements) { |
|
156 | + $this->_elements = new TXmlElementList($this); |
|
157 | + } |
|
156 | 158 | return $this->_elements; |
157 | 159 | } |
158 | 160 | |
@@ -161,8 +163,9 @@ discard block |
||
161 | 163 | */ |
162 | 164 | public function getAttributes() |
163 | 165 | { |
164 | - if(!$this->_attributes) |
|
165 | - $this->_attributes = new TMap; |
|
166 | + if(!$this->_attributes) { |
|
167 | + $this->_attributes = new TMap; |
|
168 | + } |
|
166 | 169 | return $this->_attributes; |
167 | 170 | } |
168 | 171 | |
@@ -173,9 +176,10 @@ discard block |
||
173 | 176 | { |
174 | 177 | if($this->_elements) |
175 | 178 | { |
176 | - foreach($this->_elements as $element) |
|
177 | - if($element->_tagName === $tagName) |
|
179 | + foreach($this->_elements as $element) { |
|
180 | + if($element->_tagName === $tagName) |
|
178 | 181 | return $element; |
182 | + } |
|
179 | 183 | } |
180 | 184 | return null; |
181 | 185 | } |
@@ -188,9 +192,10 @@ discard block |
||
188 | 192 | $list = new TList; |
189 | 193 | if($this->_elements) |
190 | 194 | { |
191 | - foreach($this->_elements as $element) |
|
192 | - if($element->_tagName === $tagName) |
|
195 | + foreach($this->_elements as $element) { |
|
196 | + if($element->_tagName === $tagName) |
|
193 | 197 | $list->add($element); |
198 | + } |
|
194 | 199 | } |
195 | 200 | return $list; |
196 | 201 | } |
@@ -213,18 +218,18 @@ discard block |
||
213 | 218 | if($this->getHasElement()) |
214 | 219 | { |
215 | 220 | $str = $prefix . "<{$this->_tagName}$attr>\n"; |
216 | - foreach($this->getElements() as $element) |
|
217 | - $str .= $element->toString($indent + 1) . "\n"; |
|
221 | + foreach($this->getElements() as $element) { |
|
222 | + $str .= $element->toString($indent + 1) . "\n"; |
|
223 | + } |
|
218 | 224 | $str .= $prefix . "</{$this->_tagName}>"; |
219 | 225 | return $str; |
220 | - } |
|
221 | - elseif(($value = $this->getValue()) !== '') |
|
226 | + } elseif(($value = $this->getValue()) !== '') |
|
222 | 227 | { |
223 | 228 | $value = $this->xmlEncode($value); |
224 | 229 | return $prefix . "<{$this->_tagName}$attr>$value</{$this->_tagName}>"; |
230 | + } else { |
|
231 | + return $prefix . "<{$this->_tagName}$attr />"; |
|
225 | 232 | } |
226 | - else |
|
227 | - return $prefix . "<{$this->_tagName}$attr />"; |
|
228 | 233 | } |
229 | 234 | |
230 | 235 | /** |
@@ -47,9 +47,9 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function __construct($component) |
49 | 49 | { |
50 | - if(is_string($component) && class_exists($component, false)) |
|
50 | + if (is_string($component) && class_exists($component, false)) |
|
51 | 51 | $this->_className = $component; |
52 | - elseif(is_object($component)) |
|
52 | + elseif (is_object($component)) |
|
53 | 53 | $this->_className = get_class($component); |
54 | 54 | else |
55 | 55 | throw new TInvalidDataTypeException('componentreflection_class_invalid'); |
@@ -78,41 +78,41 @@ discard block |
||
78 | 78 | $events = []; |
79 | 79 | $methods = []; |
80 | 80 | $isComponent = is_subclass_of($this->_className, 'TComponent') || strcasecmp($this->_className, 'TComponent') === 0; |
81 | - foreach($class->getMethods() as $method) |
|
81 | + foreach ($class->getMethods() as $method) |
|
82 | 82 | { |
83 | - if($method->isPublic() || $method->isProtected()) |
|
83 | + if ($method->isPublic() || $method->isProtected()) |
|
84 | 84 | { |
85 | 85 | $methodName = $method->getName(); |
86 | - if(!$method->isStatic() && $isComponent) |
|
86 | + if (!$method->isStatic() && $isComponent) |
|
87 | 87 | { |
88 | - if($this->isPropertyMethod($method)) |
|
88 | + if ($this->isPropertyMethod($method)) |
|
89 | 89 | $properties[substr($methodName, 3)] = $method; |
90 | - elseif($this->isEventMethod($method)) |
|
90 | + elseif ($this->isEventMethod($method)) |
|
91 | 91 | { |
92 | 92 | $methodName[0] = 'O'; |
93 | 93 | $events[$methodName] = $method; |
94 | 94 | } |
95 | 95 | } |
96 | - if(strncmp($methodName, '__', 2) !== 0) |
|
96 | + if (strncmp($methodName, '__', 2) !== 0) |
|
97 | 97 | $methods[$methodName] = $method; |
98 | 98 | } |
99 | 99 | } |
100 | 100 | $reserved = []; |
101 | 101 | ksort($properties); |
102 | - foreach($properties as $name => $method) |
|
102 | + foreach ($properties as $name => $method) |
|
103 | 103 | { |
104 | 104 | $this->_properties[$name] = [ |
105 | 105 | 'type' => $this->determinePropertyType($method), |
106 | - 'readonly' => !$class->hasMethod('set' . $name), |
|
106 | + 'readonly' => !$class->hasMethod('set'.$name), |
|
107 | 107 | 'protected' => $method->isProtected(), |
108 | 108 | 'class' => $method->getDeclaringClass()->getName(), |
109 | 109 | 'comments' => $method->getDocComment() |
110 | 110 | ]; |
111 | - $reserved['get' . strtolower($name)] = 1; |
|
112 | - $reserved['set' . strtolower($name)] = 1; |
|
111 | + $reserved['get'.strtolower($name)] = 1; |
|
112 | + $reserved['set'.strtolower($name)] = 1; |
|
113 | 113 | } |
114 | 114 | ksort($events); |
115 | - foreach($events as $name => $method) |
|
115 | + foreach ($events as $name => $method) |
|
116 | 116 | { |
117 | 117 | $this->_events[$name] = [ |
118 | 118 | 'class' => $method->getDeclaringClass()->getName(), |
@@ -122,9 +122,9 @@ discard block |
||
122 | 122 | $reserved[strtolower($name)] = 1; |
123 | 123 | } |
124 | 124 | ksort($methods); |
125 | - foreach($methods as $name => $method) |
|
125 | + foreach ($methods as $name => $method) |
|
126 | 126 | { |
127 | - if(!isset($reserved[strtolower($name)])) |
|
127 | + if (!isset($reserved[strtolower($name)])) |
|
128 | 128 | $this->_methods[$name] = [ |
129 | 129 | 'class' => $method->getDeclaringClass()->getName(), |
130 | 130 | 'protected' => $method->isProtected(), |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | protected function determinePropertyType($method) |
144 | 144 | { |
145 | 145 | $comment = $method->getDocComment(); |
146 | - if(preg_match('/@return\\s+(.*?)\\s+/', $comment, $matches)) |
|
146 | + if (preg_match('/@return\\s+(.*?)\\s+/', $comment, $matches)) |
|
147 | 147 | return $matches[1]; |
148 | 148 | else |
149 | 149 | return '{unknown}'; |
@@ -47,12 +47,13 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function __construct($component) |
49 | 49 | { |
50 | - if(is_string($component) && class_exists($component, false)) |
|
51 | - $this->_className = $component; |
|
52 | - elseif(is_object($component)) |
|
53 | - $this->_className = get_class($component); |
|
54 | - else |
|
55 | - throw new TInvalidDataTypeException('componentreflection_class_invalid'); |
|
50 | + if(is_string($component) && class_exists($component, false)) { |
|
51 | + $this->_className = $component; |
|
52 | + } elseif(is_object($component)) { |
|
53 | + $this->_className = get_class($component); |
|
54 | + } else { |
|
55 | + throw new TInvalidDataTypeException('componentreflection_class_invalid'); |
|
56 | + } |
|
56 | 57 | $this->reflect(); |
57 | 58 | } |
58 | 59 | |
@@ -85,16 +86,17 @@ discard block |
||
85 | 86 | $methodName = $method->getName(); |
86 | 87 | if(!$method->isStatic() && $isComponent) |
87 | 88 | { |
88 | - if($this->isPropertyMethod($method)) |
|
89 | - $properties[substr($methodName, 3)] = $method; |
|
90 | - elseif($this->isEventMethod($method)) |
|
89 | + if($this->isPropertyMethod($method)) { |
|
90 | + $properties[substr($methodName, 3)] = $method; |
|
91 | + } elseif($this->isEventMethod($method)) |
|
91 | 92 | { |
92 | 93 | $methodName[0] = 'O'; |
93 | 94 | $events[$methodName] = $method; |
94 | 95 | } |
95 | 96 | } |
96 | - if(strncmp($methodName, '__', 2) !== 0) |
|
97 | - $methods[$methodName] = $method; |
|
97 | + if(strncmp($methodName, '__', 2) !== 0) { |
|
98 | + $methods[$methodName] = $method; |
|
99 | + } |
|
98 | 100 | } |
99 | 101 | } |
100 | 102 | $reserved = []; |
@@ -124,13 +126,14 @@ discard block |
||
124 | 126 | ksort($methods); |
125 | 127 | foreach($methods as $name => $method) |
126 | 128 | { |
127 | - if(!isset($reserved[strtolower($name)])) |
|
128 | - $this->_methods[$name] = [ |
|
129 | + if(!isset($reserved[strtolower($name)])) { |
|
130 | + $this->_methods[$name] = [ |
|
129 | 131 | 'class' => $method->getDeclaringClass()->getName(), |
130 | 132 | 'protected' => $method->isProtected(), |
131 | 133 | 'static' => $method->isStatic(), |
132 | 134 | 'comments' => $method->getDocComment() |
133 | 135 | ]; |
136 | + } |
|
134 | 137 | } |
135 | 138 | } |
136 | 139 | |
@@ -143,10 +146,11 @@ discard block |
||
143 | 146 | protected function determinePropertyType($method) |
144 | 147 | { |
145 | 148 | $comment = $method->getDocComment(); |
146 | - if(preg_match('/@return\\s+(.*?)\\s+/', $comment, $matches)) |
|
147 | - return $matches[1]; |
|
148 | - else |
|
149 | - return '{unknown}'; |
|
149 | + if(preg_match('/@return\\s+(.*?)\\s+/', $comment, $matches)) { |
|
150 | + return $matches[1]; |
|
151 | + } else { |
|
152 | + return '{unknown}'; |
|
153 | + } |
|
150 | 154 | } |
151 | 155 | |
152 | 156 | /** |
@@ -55,8 +55,8 @@ discard block |
||
55 | 55 | array_shift($args); |
56 | 56 | $n = count($args); |
57 | 57 | $tokens = []; |
58 | - for($i = 0;$i < $n;++$i) |
|
59 | - $tokens['{' . $i . '}'] = TPropertyValue::ensureString($args[$i]); |
|
58 | + for ($i = 0; $i < $n; ++$i) |
|
59 | + $tokens['{'.$i.'}'] = TPropertyValue::ensureString($args[$i]); |
|
60 | 60 | parent::__construct(strtr($errorMessage, $tokens)); |
61 | 61 | } |
62 | 62 | |
@@ -72,11 +72,11 @@ discard block |
||
72 | 72 | // Cache messages |
73 | 73 | if (!isset(self::$_messageCache[$msgFile])) |
74 | 74 | { |
75 | - if(($entries = @file($msgFile)) !== false) |
|
75 | + if (($entries = @file($msgFile)) !== false) |
|
76 | 76 | { |
77 | - foreach($entries as $entry) |
|
77 | + foreach ($entries as $entry) |
|
78 | 78 | { |
79 | - list($code, $message) = array_merge(explode('=', $entry, 2), [ '' ]); |
|
79 | + list($code, $message) = array_merge(explode('=', $entry, 2), ['']); |
|
80 | 80 | self::$_messageCache[$msgFile][trim($code)] = trim($message); |
81 | 81 | } |
82 | 82 | } |
@@ -90,9 +90,9 @@ discard block |
||
90 | 90 | protected function getErrorMessageFile() |
91 | 91 | { |
92 | 92 | $lang = Prado::getPreferredLanguage(); |
93 | - $msgFile = Prado::getFrameworkPath() . '/Exceptions/messages/messages-' . $lang . '.txt'; |
|
94 | - if(!is_file($msgFile)) |
|
95 | - $msgFile = Prado::getFrameworkPath() . '/Exceptions/messages/messages.txt'; |
|
93 | + $msgFile = Prado::getFrameworkPath().'/Exceptions/messages/messages-'.$lang.'.txt'; |
|
94 | + if (!is_file($msgFile)) |
|
95 | + $msgFile = Prado::getFrameworkPath().'/Exceptions/messages/messages.txt'; |
|
96 | 96 | return $msgFile; |
97 | 97 | } |
98 | 98 |
@@ -55,8 +55,9 @@ discard block |
||
55 | 55 | array_shift($args); |
56 | 56 | $n = count($args); |
57 | 57 | $tokens = []; |
58 | - for($i = 0;$i < $n;++$i) |
|
59 | - $tokens['{' . $i . '}'] = TPropertyValue::ensureString($args[$i]); |
|
58 | + for($i = 0;$i < $n;++$i) { |
|
59 | + $tokens['{' . $i . '}'] = TPropertyValue::ensureString($args[$i]); |
|
60 | + } |
|
60 | 61 | parent::__construct(strtr($errorMessage, $tokens)); |
61 | 62 | } |
62 | 63 | |
@@ -91,8 +92,9 @@ discard block |
||
91 | 92 | { |
92 | 93 | $lang = Prado::getPreferredLanguage(); |
93 | 94 | $msgFile = Prado::getFrameworkPath() . '/Exceptions/messages/messages-' . $lang . '.txt'; |
94 | - if(!is_file($msgFile)) |
|
95 | - $msgFile = Prado::getFrameworkPath() . '/Exceptions/messages/messages.txt'; |
|
95 | + if(!is_file($msgFile)) { |
|
96 | + $msgFile = Prado::getFrameworkPath() . '/Exceptions/messages/messages.txt'; |
|
97 | + } |
|
96 | 98 | return $msgFile; |
97 | 99 | } |
98 | 100 |
@@ -91,8 +91,8 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public function getErrorTemplatePath() |
93 | 93 | { |
94 | - if($this->_templatePath === null) |
|
95 | - $this->_templatePath = Prado::getFrameworkPath() . '/Exceptions/templates'; |
|
94 | + if ($this->_templatePath === null) |
|
95 | + $this->_templatePath = Prado::getFrameworkPath().'/Exceptions/templates'; |
|
96 | 96 | return $this->_templatePath; |
97 | 97 | } |
98 | 98 | |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | */ |
105 | 105 | public function setErrorTemplatePath($value) |
106 | 106 | { |
107 | - if(($templatePath = Prado::getPathOfNamespace($value)) !== null && is_dir($templatePath)) |
|
107 | + if (($templatePath = Prado::getPathOfNamespace($value)) !== null && is_dir($templatePath)) |
|
108 | 108 | $this->_templatePath = $templatePath; |
109 | 109 | else |
110 | 110 | throw new TConfigurationException('errorhandler_errortemplatepath_invalid', $value); |
@@ -128,18 +128,18 @@ discard block |
||
128 | 128 | restore_error_handler(); |
129 | 129 | restore_exception_handler(); |
130 | 130 | // ensure that we do not enter infinite loop of error handling |
131 | - if($handling) |
|
131 | + if ($handling) |
|
132 | 132 | $this->handleRecursiveError($param); |
133 | 133 | else |
134 | 134 | { |
135 | 135 | $handling = true; |
136 | - if(($response = $this->getResponse()) !== null) |
|
136 | + if (($response = $this->getResponse()) !== null) |
|
137 | 137 | $response->clear(); |
138 | - if(!headers_sent()) |
|
138 | + if (!headers_sent()) |
|
139 | 139 | header('Content-Type: text/html; charset=UTF-8'); |
140 | - if($param instanceof THttpException) |
|
140 | + if ($param instanceof THttpException) |
|
141 | 141 | $this->handleExternalError($param->getStatusCode(), $param); |
142 | - elseif($this->getApplication()->getMode() === TApplicationMode::Debug) |
|
142 | + elseif ($this->getApplication()->getMode() === TApplicationMode::Debug) |
|
143 | 143 | $this->displayException($param); |
144 | 144 | else |
145 | 145 | $this->handleExternalError(500, $param); |
@@ -156,9 +156,9 @@ discard block |
||
156 | 156 | protected static function hideSecurityRelated($value, $exception = null) |
157 | 157 | { |
158 | 158 | $aRpl = []; |
159 | - if($exception !== null && $exception instanceof \Exception) |
|
159 | + if ($exception !== null && $exception instanceof \Exception) |
|
160 | 160 | { |
161 | - if($exception instanceof TPhpFatalErrorException && |
|
161 | + if ($exception instanceof TPhpFatalErrorException && |
|
162 | 162 | function_exists('xdebug_get_function_stack')) |
163 | 163 | { |
164 | 164 | $aTrace = array_slice(array_reverse(xdebug_get_function_stack()), self::FATAL_ERROR_TRACE_DROP_LINES, -1); |
@@ -166,16 +166,16 @@ discard block |
||
166 | 166 | $aTrace = $exception->getTrace(); |
167 | 167 | } |
168 | 168 | |
169 | - foreach($aTrace as $item) |
|
169 | + foreach ($aTrace as $item) |
|
170 | 170 | { |
171 | - if(isset($item['file'])) |
|
172 | - $aRpl[dirname($item['file']) . DIRECTORY_SEPARATOR] = '<hidden>' . DIRECTORY_SEPARATOR; |
|
171 | + if (isset($item['file'])) |
|
172 | + $aRpl[dirname($item['file']).DIRECTORY_SEPARATOR] = '<hidden>'.DIRECTORY_SEPARATOR; |
|
173 | 173 | } |
174 | 174 | } |
175 | 175 | $aRpl[$_SERVER['DOCUMENT_ROOT']] = '${DocumentRoot}'; |
176 | 176 | $aRpl[str_replace('/', DIRECTORY_SEPARATOR, $_SERVER['DOCUMENT_ROOT'])] = '${DocumentRoot}'; |
177 | - $aRpl[PRADO_DIR . DIRECTORY_SEPARATOR] = '${PradoFramework}' . DIRECTORY_SEPARATOR; |
|
178 | - if(isset($aRpl[DIRECTORY_SEPARATOR])) unset($aRpl[DIRECTORY_SEPARATOR]); |
|
177 | + $aRpl[PRADO_DIR.DIRECTORY_SEPARATOR] = '${PradoFramework}'.DIRECTORY_SEPARATOR; |
|
178 | + if (isset($aRpl[DIRECTORY_SEPARATOR])) unset($aRpl[DIRECTORY_SEPARATOR]); |
|
179 | 179 | $aRpl = array_reverse($aRpl, true); |
180 | 180 | |
181 | 181 | return str_replace(array_keys($aRpl), $aRpl, $value); |
@@ -190,18 +190,18 @@ discard block |
||
190 | 190 | */ |
191 | 191 | protected function handleExternalError($statusCode, $exception) |
192 | 192 | { |
193 | - if(!($exception instanceof THttpException)) |
|
193 | + if (!($exception instanceof THttpException)) |
|
194 | 194 | error_log($exception->__toString()); |
195 | 195 | |
196 | 196 | $content = $this->getErrorTemplate($statusCode, $exception); |
197 | 197 | |
198 | - $serverAdmin = isset($_SERVER['SERVER_ADMIN'])?$_SERVER['SERVER_ADMIN']:''; |
|
198 | + $serverAdmin = isset($_SERVER['SERVER_ADMIN']) ? $_SERVER['SERVER_ADMIN'] : ''; |
|
199 | 199 | |
200 | 200 | $isDebug = $this->getApplication()->getMode() === TApplicationMode::Debug; |
201 | 201 | |
202 | 202 | $errorMessage = $exception->getMessage(); |
203 | - if($isDebug) |
|
204 | - $version = $_SERVER['SERVER_SOFTWARE'] . ' <a href="https://github.com/pradosoft/prado">PRADO</a>/' . Prado::getVersion(); |
|
203 | + if ($isDebug) |
|
204 | + $version = $_SERVER['SERVER_SOFTWARE'].' <a href="https://github.com/pradosoft/prado">PRADO</a>/'.Prado::getVersion(); |
|
205 | 205 | else |
206 | 206 | { |
207 | 207 | $version = ''; |
@@ -229,16 +229,16 @@ discard block |
||
229 | 229 | */ |
230 | 230 | protected function handleRecursiveError($exception) |
231 | 231 | { |
232 | - if($this->getApplication()->getMode() === TApplicationMode::Debug) |
|
232 | + if ($this->getApplication()->getMode() === TApplicationMode::Debug) |
|
233 | 233 | { |
234 | 234 | echo "<html><head><title>Recursive Error</title></head>\n"; |
235 | 235 | echo "<body><h1>Recursive Error</h1>\n"; |
236 | - echo "<pre>" . $exception->__toString() . "</pre>\n"; |
|
236 | + echo "<pre>".$exception->__toString()."</pre>\n"; |
|
237 | 237 | echo "</body></html>"; |
238 | 238 | } |
239 | 239 | else |
240 | 240 | { |
241 | - error_log("Error happened while processing an existing error:\n" . $exception->__toString()); |
|
241 | + error_log("Error happened while processing an existing error:\n".$exception->__toString()); |
|
242 | 242 | header('HTTP/1.0 500 Internal Error'); |
243 | 243 | } |
244 | 244 | } |
@@ -252,25 +252,25 @@ discard block |
||
252 | 252 | */ |
253 | 253 | protected function displayException($exception) |
254 | 254 | { |
255 | - if(php_sapi_name() === 'cli') |
|
255 | + if (php_sapi_name() === 'cli') |
|
256 | 256 | { |
257 | - echo $exception->getMessage() . "\n"; |
|
257 | + echo $exception->getMessage()."\n"; |
|
258 | 258 | echo $this->getExactTraceAsString($exception); |
259 | 259 | return; |
260 | 260 | } |
261 | 261 | |
262 | - if($exception instanceof TTemplateException) |
|
262 | + if ($exception instanceof TTemplateException) |
|
263 | 263 | { |
264 | 264 | $fileName = $exception->getTemplateFile(); |
265 | - $lines = empty($fileName)?explode("\n", $exception->getTemplateSource()):@file($fileName); |
|
265 | + $lines = empty($fileName) ?explode("\n", $exception->getTemplateSource()) : @file($fileName); |
|
266 | 266 | $source = $this->getSourceCode($lines, $exception->getLineNumber()); |
267 | - if($fileName === '') |
|
267 | + if ($fileName === '') |
|
268 | 268 | $fileName = '---embedded template---'; |
269 | 269 | $errorLine = $exception->getLineNumber(); |
270 | 270 | } |
271 | 271 | else |
272 | 272 | { |
273 | - if(($trace = $this->getExactTrace($exception)) !== null) |
|
273 | + if (($trace = $this->getExactTrace($exception)) !== null) |
|
274 | 274 | { |
275 | 275 | $fileName = $trace['file']; |
276 | 276 | $errorLine = $trace['line']; |
@@ -283,15 +283,15 @@ discard block |
||
283 | 283 | $source = $this->getSourceCode(@file($fileName), $errorLine); |
284 | 284 | } |
285 | 285 | |
286 | - if($this->getApplication()->getMode() === TApplicationMode::Debug) |
|
287 | - $version = $_SERVER['SERVER_SOFTWARE'] . ' <a href="https://github.com/pradosoft/prado">PRADO</a>/' . Prado::getVersion(); |
|
286 | + if ($this->getApplication()->getMode() === TApplicationMode::Debug) |
|
287 | + $version = $_SERVER['SERVER_SOFTWARE'].' <a href="https://github.com/pradosoft/prado">PRADO</a>/'.Prado::getVersion(); |
|
288 | 288 | else |
289 | 289 | $version = ''; |
290 | 290 | |
291 | 291 | $tokens = [ |
292 | 292 | '%%ErrorType%%' => get_class($exception), |
293 | 293 | '%%ErrorMessage%%' => $this->addLink(htmlspecialchars($exception->getMessage())), |
294 | - '%%SourceFile%%' => htmlspecialchars($fileName) . ' (' . $errorLine . ')', |
|
294 | + '%%SourceFile%%' => htmlspecialchars($fileName).' ('.$errorLine.')', |
|
295 | 295 | '%%SourceCode%%' => $source, |
296 | 296 | '%%StackTrace%%' => htmlspecialchars($this->getExactTraceAsString($exception)), |
297 | 297 | '%%Version%%' => $version, |
@@ -313,10 +313,10 @@ discard block |
||
313 | 313 | protected function getExceptionTemplate($exception) |
314 | 314 | { |
315 | 315 | $lang = Prado::getPreferredLanguage(); |
316 | - $exceptionFile = Prado::getFrameworkPath() . '/Exceptions/templates/' . self::EXCEPTION_FILE_NAME . '-' . $lang . '.html'; |
|
317 | - if(!is_file($exceptionFile)) |
|
318 | - $exceptionFile = Prado::getFrameworkPath() . '/Exceptions/templates/' . self::EXCEPTION_FILE_NAME . '.html'; |
|
319 | - if(($content = @file_get_contents($exceptionFile)) === false) |
|
316 | + $exceptionFile = Prado::getFrameworkPath().'/Exceptions/templates/'.self::EXCEPTION_FILE_NAME.'-'.$lang.'.html'; |
|
317 | + if (!is_file($exceptionFile)) |
|
318 | + $exceptionFile = Prado::getFrameworkPath().'/Exceptions/templates/'.self::EXCEPTION_FILE_NAME.'.html'; |
|
319 | + if (($content = @file_get_contents($exceptionFile)) === false) |
|
320 | 320 | die("Unable to open exception template file '$exceptionFile'."); |
321 | 321 | return $content; |
322 | 322 | } |
@@ -339,17 +339,17 @@ discard block |
||
339 | 339 | */ |
340 | 340 | protected function getErrorTemplate($statusCode, $exception) |
341 | 341 | { |
342 | - $base = $this->getErrorTemplatePath() . DIRECTORY_SEPARATOR . self::ERROR_FILE_NAME; |
|
342 | + $base = $this->getErrorTemplatePath().DIRECTORY_SEPARATOR.self::ERROR_FILE_NAME; |
|
343 | 343 | $lang = Prado::getPreferredLanguage(); |
344 | - if(is_file("$base$statusCode-$lang.html")) |
|
344 | + if (is_file("$base$statusCode-$lang.html")) |
|
345 | 345 | $errorFile = "$base$statusCode-$lang.html"; |
346 | - elseif(is_file("$base$statusCode.html")) |
|
346 | + elseif (is_file("$base$statusCode.html")) |
|
347 | 347 | $errorFile = "$base$statusCode.html"; |
348 | - elseif(is_file("$base-$lang.html")) |
|
348 | + elseif (is_file("$base-$lang.html")) |
|
349 | 349 | $errorFile = "$base-$lang.html"; |
350 | 350 | else |
351 | 351 | $errorFile = "$base.html"; |
352 | - if(($content = @file_get_contents($errorFile)) === false) |
|
352 | + if (($content = @file_get_contents($errorFile)) === false) |
|
353 | 353 | die("Unable to open error template file '$errorFile'."); |
354 | 354 | return $content; |
355 | 355 | } |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | private function getExactTrace($exception) |
358 | 358 | { |
359 | 359 | $result = null; |
360 | - if($exception instanceof TPhpFatalErrorException && |
|
360 | + if ($exception instanceof TPhpFatalErrorException && |
|
361 | 361 | function_exists('xdebug_get_function_stack')) |
362 | 362 | { |
363 | 363 | $trace = array_slice(array_reverse(xdebug_get_function_stack()), self::FATAL_ERROR_TRACE_DROP_LINES, -1); |
@@ -367,17 +367,17 @@ discard block |
||
367 | 367 | |
368 | 368 | // if PHP exception, we want to show the 2nd stack level context |
369 | 369 | // because the 1st stack level is of little use (it's in error handler) |
370 | - if($exception instanceof TPhpErrorException) { |
|
371 | - if(isset($trace[0]['file'])) |
|
370 | + if ($exception instanceof TPhpErrorException) { |
|
371 | + if (isset($trace[0]['file'])) |
|
372 | 372 | $result = $trace[0]; |
373 | - elseif(isset($trace[1])) |
|
373 | + elseif (isset($trace[1])) |
|
374 | 374 | $result = $trace[1]; |
375 | - } elseif($exception instanceof TInvalidOperationException) { |
|
375 | + } elseif ($exception instanceof TInvalidOperationException) { |
|
376 | 376 | // in case of getter or setter error, find out the exact file and row |
377 | - if(($result = $this->getPropertyAccessTrace($trace, '__get')) === null) |
|
377 | + if (($result = $this->getPropertyAccessTrace($trace, '__get')) === null) |
|
378 | 378 | $result = $this->getPropertyAccessTrace($trace, '__set'); |
379 | 379 | } |
380 | - if($result !== null && strpos($result['file'], ': eval()\'d code') !== false) |
|
380 | + if ($result !== null && strpos($result['file'], ': eval()\'d code') !== false) |
|
381 | 381 | return null; |
382 | 382 | |
383 | 383 | return $result; |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | |
386 | 386 | private function getExactTraceAsString($exception) |
387 | 387 | { |
388 | - if($exception instanceof TPhpFatalErrorException && |
|
388 | + if ($exception instanceof TPhpFatalErrorException && |
|
389 | 389 | function_exists('xdebug_get_function_stack')) |
390 | 390 | { |
391 | 391 | $trace = array_slice(array_reverse(xdebug_get_function_stack()), self::FATAL_ERROR_TRACE_DROP_LINES, -1); |
@@ -393,14 +393,14 @@ discard block |
||
393 | 393 | $row = 0; |
394 | 394 | |
395 | 395 | // try to mimic Exception::getTraceAsString() |
396 | - foreach($trace as $line) |
|
396 | + foreach ($trace as $line) |
|
397 | 397 | { |
398 | - if(array_key_exists('function', $line)) |
|
399 | - $func = $line['function'] . '(' . implode(',', $line['params']) . ')'; |
|
398 | + if (array_key_exists('function', $line)) |
|
399 | + $func = $line['function'].'('.implode(',', $line['params']).')'; |
|
400 | 400 | else |
401 | 401 | $func = 'unknown'; |
402 | 402 | |
403 | - $txt .= '#' . $row . ' ' . $line['file'] . '(' . $line['line'] . '): ' . $func . "\n"; |
|
403 | + $txt .= '#'.$row.' '.$line['file'].'('.$line['line'].'): '.$func."\n"; |
|
404 | 404 | $row++; |
405 | 405 | } |
406 | 406 | |
@@ -413,9 +413,9 @@ discard block |
||
413 | 413 | private function getPropertyAccessTrace($trace, $pattern) |
414 | 414 | { |
415 | 415 | $result = null; |
416 | - foreach($trace as $t) |
|
416 | + foreach ($trace as $t) |
|
417 | 417 | { |
418 | - if(isset($t['function']) && $t['function'] === $pattern) |
|
418 | + if (isset($t['function']) && $t['function'] === $pattern) |
|
419 | 419 | $result = $t; |
420 | 420 | else |
421 | 421 | break; |
@@ -425,16 +425,16 @@ discard block |
||
425 | 425 | |
426 | 426 | private function getSourceCode($lines, $errorLine) |
427 | 427 | { |
428 | - $beginLine = $errorLine - self::SOURCE_LINES >= 0?$errorLine - self::SOURCE_LINES:0; |
|
429 | - $endLine = $errorLine + self::SOURCE_LINES <= count($lines)?$errorLine + self::SOURCE_LINES:count($lines); |
|
428 | + $beginLine = $errorLine - self::SOURCE_LINES >= 0 ? $errorLine - self::SOURCE_LINES : 0; |
|
429 | + $endLine = $errorLine + self::SOURCE_LINES <= count($lines) ? $errorLine + self::SOURCE_LINES : count($lines); |
|
430 | 430 | |
431 | 431 | $source = ''; |
432 | - for($i = $beginLine;$i < $endLine;++$i) |
|
432 | + for ($i = $beginLine; $i < $endLine; ++$i) |
|
433 | 433 | { |
434 | - if($i === $errorLine - 1) |
|
434 | + if ($i === $errorLine - 1) |
|
435 | 435 | { |
436 | 436 | $line = htmlspecialchars(sprintf("%04d: %s", $i + 1, str_replace("\t", ' ', $lines[$i]))); |
437 | - $source .= "<div class=\"error\">" . $line . "</div>"; |
|
437 | + $source .= "<div class=\"error\">".$line."</div>"; |
|
438 | 438 | } |
439 | 439 | else |
440 | 440 | $source .= htmlspecialchars(sprintf("%04d: %s", $i + 1, str_replace("\t", ' ', $lines[$i]))); |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | |
445 | 445 | private function addLink($message) { |
446 | 446 | if (null !== ($class = $this->getErrorClassNameSpace($message))) { |
447 | - return str_replace($class['name'], '<a href="' . $class['url'] . '" target="_blank">' . $class['name'] . '</a>', $message); |
|
447 | + return str_replace($class['name'], '<a href="'.$class['url'].'" target="_blank">'.$class['name'].'</a>', $message); |
|
448 | 448 | } |
449 | 449 | return $message; |
450 | 450 | } |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | } |
463 | 463 | $classname = $function->getNamespaceName(); |
464 | 464 | return [ |
465 | - 'url' => 'http://pradosoft.github.io/docs/manual/class-' . str_replace('\\', '.', (string) $classname) . '.' . $class . '.html', |
|
465 | + 'url' => 'http://pradosoft.github.io/docs/manual/class-'.str_replace('\\', '.', (string) $classname).'.'.$class.'.html', |
|
466 | 466 | 'name' => $class, |
467 | 467 | ]; |
468 | 468 | } |
@@ -91,8 +91,9 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public function getErrorTemplatePath() |
93 | 93 | { |
94 | - if($this->_templatePath === null) |
|
95 | - $this->_templatePath = Prado::getFrameworkPath() . '/Exceptions/templates'; |
|
94 | + if($this->_templatePath === null) { |
|
95 | + $this->_templatePath = Prado::getFrameworkPath() . '/Exceptions/templates'; |
|
96 | + } |
|
96 | 97 | return $this->_templatePath; |
97 | 98 | } |
98 | 99 | |
@@ -104,10 +105,11 @@ discard block |
||
104 | 105 | */ |
105 | 106 | public function setErrorTemplatePath($value) |
106 | 107 | { |
107 | - if(($templatePath = Prado::getPathOfNamespace($value)) !== null && is_dir($templatePath)) |
|
108 | - $this->_templatePath = $templatePath; |
|
109 | - else |
|
110 | - throw new TConfigurationException('errorhandler_errortemplatepath_invalid', $value); |
|
108 | + if(($templatePath = Prado::getPathOfNamespace($value)) !== null && is_dir($templatePath)) { |
|
109 | + $this->_templatePath = $templatePath; |
|
110 | + } else { |
|
111 | + throw new TConfigurationException('errorhandler_errortemplatepath_invalid', $value); |
|
112 | + } |
|
111 | 113 | } |
112 | 114 | |
113 | 115 | /** |
@@ -128,21 +130,24 @@ discard block |
||
128 | 130 | restore_error_handler(); |
129 | 131 | restore_exception_handler(); |
130 | 132 | // ensure that we do not enter infinite loop of error handling |
131 | - if($handling) |
|
132 | - $this->handleRecursiveError($param); |
|
133 | - else |
|
133 | + if($handling) { |
|
134 | + $this->handleRecursiveError($param); |
|
135 | + } else |
|
134 | 136 | { |
135 | 137 | $handling = true; |
136 | - if(($response = $this->getResponse()) !== null) |
|
137 | - $response->clear(); |
|
138 | - if(!headers_sent()) |
|
139 | - header('Content-Type: text/html; charset=UTF-8'); |
|
140 | - if($param instanceof THttpException) |
|
141 | - $this->handleExternalError($param->getStatusCode(), $param); |
|
142 | - elseif($this->getApplication()->getMode() === TApplicationMode::Debug) |
|
143 | - $this->displayException($param); |
|
144 | - else |
|
145 | - $this->handleExternalError(500, $param); |
|
138 | + if(($response = $this->getResponse()) !== null) { |
|
139 | + $response->clear(); |
|
140 | + } |
|
141 | + if(!headers_sent()) { |
|
142 | + header('Content-Type: text/html; charset=UTF-8'); |
|
143 | + } |
|
144 | + if($param instanceof THttpException) { |
|
145 | + $this->handleExternalError($param->getStatusCode(), $param); |
|
146 | + } elseif($this->getApplication()->getMode() === TApplicationMode::Debug) { |
|
147 | + $this->displayException($param); |
|
148 | + } else { |
|
149 | + $this->handleExternalError(500, $param); |
|
150 | + } |
|
146 | 151 | } |
147 | 152 | } |
148 | 153 | |
@@ -168,14 +173,17 @@ discard block |
||
168 | 173 | |
169 | 174 | foreach($aTrace as $item) |
170 | 175 | { |
171 | - if(isset($item['file'])) |
|
172 | - $aRpl[dirname($item['file']) . DIRECTORY_SEPARATOR] = '<hidden>' . DIRECTORY_SEPARATOR; |
|
176 | + if(isset($item['file'])) { |
|
177 | + $aRpl[dirname($item['file']) . DIRECTORY_SEPARATOR] = '<hidden>' . DIRECTORY_SEPARATOR; |
|
178 | + } |
|
173 | 179 | } |
174 | 180 | } |
175 | 181 | $aRpl[$_SERVER['DOCUMENT_ROOT']] = '${DocumentRoot}'; |
176 | 182 | $aRpl[str_replace('/', DIRECTORY_SEPARATOR, $_SERVER['DOCUMENT_ROOT'])] = '${DocumentRoot}'; |
177 | 183 | $aRpl[PRADO_DIR . DIRECTORY_SEPARATOR] = '${PradoFramework}' . DIRECTORY_SEPARATOR; |
178 | - if(isset($aRpl[DIRECTORY_SEPARATOR])) unset($aRpl[DIRECTORY_SEPARATOR]); |
|
184 | + if(isset($aRpl[DIRECTORY_SEPARATOR])) { |
|
185 | + unset($aRpl[DIRECTORY_SEPARATOR]); |
|
186 | + } |
|
179 | 187 | $aRpl = array_reverse($aRpl, true); |
180 | 188 | |
181 | 189 | return str_replace(array_keys($aRpl), $aRpl, $value); |
@@ -190,8 +198,9 @@ discard block |
||
190 | 198 | */ |
191 | 199 | protected function handleExternalError($statusCode, $exception) |
192 | 200 | { |
193 | - if(!($exception instanceof THttpException)) |
|
194 | - error_log($exception->__toString()); |
|
201 | + if(!($exception instanceof THttpException)) { |
|
202 | + error_log($exception->__toString()); |
|
203 | + } |
|
195 | 204 | |
196 | 205 | $content = $this->getErrorTemplate($statusCode, $exception); |
197 | 206 | |
@@ -200,9 +209,9 @@ discard block |
||
200 | 209 | $isDebug = $this->getApplication()->getMode() === TApplicationMode::Debug; |
201 | 210 | |
202 | 211 | $errorMessage = $exception->getMessage(); |
203 | - if($isDebug) |
|
204 | - $version = $_SERVER['SERVER_SOFTWARE'] . ' <a href="https://github.com/pradosoft/prado">PRADO</a>/' . Prado::getVersion(); |
|
205 | - else |
|
212 | + if($isDebug) { |
|
213 | + $version = $_SERVER['SERVER_SOFTWARE'] . ' <a href="https://github.com/pradosoft/prado">PRADO</a>/' . Prado::getVersion(); |
|
214 | + } else |
|
206 | 215 | { |
207 | 216 | $version = ''; |
208 | 217 | $errorMessage = self::hideSecurityRelated($errorMessage, $exception); |
@@ -235,8 +244,7 @@ discard block |
||
235 | 244 | echo "<body><h1>Recursive Error</h1>\n"; |
236 | 245 | echo "<pre>" . $exception->__toString() . "</pre>\n"; |
237 | 246 | echo "</body></html>"; |
238 | - } |
|
239 | - else |
|
247 | + } else |
|
240 | 248 | { |
241 | 249 | error_log("Error happened while processing an existing error:\n" . $exception->__toString()); |
242 | 250 | header('HTTP/1.0 500 Internal Error'); |
@@ -264,18 +272,17 @@ discard block |
||
264 | 272 | $fileName = $exception->getTemplateFile(); |
265 | 273 | $lines = empty($fileName)?explode("\n", $exception->getTemplateSource()):@file($fileName); |
266 | 274 | $source = $this->getSourceCode($lines, $exception->getLineNumber()); |
267 | - if($fileName === '') |
|
268 | - $fileName = '---embedded template---'; |
|
275 | + if($fileName === '') { |
|
276 | + $fileName = '---embedded template---'; |
|
277 | + } |
|
269 | 278 | $errorLine = $exception->getLineNumber(); |
270 | - } |
|
271 | - else |
|
279 | + } else |
|
272 | 280 | { |
273 | 281 | if(($trace = $this->getExactTrace($exception)) !== null) |
274 | 282 | { |
275 | 283 | $fileName = $trace['file']; |
276 | 284 | $errorLine = $trace['line']; |
277 | - } |
|
278 | - else |
|
285 | + } else |
|
279 | 286 | { |
280 | 287 | $fileName = $exception->getFile(); |
281 | 288 | $errorLine = $exception->getLine(); |
@@ -283,10 +290,11 @@ discard block |
||
283 | 290 | $source = $this->getSourceCode(@file($fileName), $errorLine); |
284 | 291 | } |
285 | 292 | |
286 | - if($this->getApplication()->getMode() === TApplicationMode::Debug) |
|
287 | - $version = $_SERVER['SERVER_SOFTWARE'] . ' <a href="https://github.com/pradosoft/prado">PRADO</a>/' . Prado::getVersion(); |
|
288 | - else |
|
289 | - $version = ''; |
|
293 | + if($this->getApplication()->getMode() === TApplicationMode::Debug) { |
|
294 | + $version = $_SERVER['SERVER_SOFTWARE'] . ' <a href="https://github.com/pradosoft/prado">PRADO</a>/' . Prado::getVersion(); |
|
295 | + } else { |
|
296 | + $version = ''; |
|
297 | + } |
|
290 | 298 | |
291 | 299 | $tokens = [ |
292 | 300 | '%%ErrorType%%' => get_class($exception), |
@@ -314,10 +322,12 @@ discard block |
||
314 | 322 | { |
315 | 323 | $lang = Prado::getPreferredLanguage(); |
316 | 324 | $exceptionFile = Prado::getFrameworkPath() . '/Exceptions/templates/' . self::EXCEPTION_FILE_NAME . '-' . $lang . '.html'; |
317 | - if(!is_file($exceptionFile)) |
|
318 | - $exceptionFile = Prado::getFrameworkPath() . '/Exceptions/templates/' . self::EXCEPTION_FILE_NAME . '.html'; |
|
319 | - if(($content = @file_get_contents($exceptionFile)) === false) |
|
320 | - die("Unable to open exception template file '$exceptionFile'."); |
|
325 | + if(!is_file($exceptionFile)) { |
|
326 | + $exceptionFile = Prado::getFrameworkPath() . '/Exceptions/templates/' . self::EXCEPTION_FILE_NAME . '.html'; |
|
327 | + } |
|
328 | + if(($content = @file_get_contents($exceptionFile)) === false) { |
|
329 | + die("Unable to open exception template file '$exceptionFile'."); |
|
330 | + } |
|
321 | 331 | return $content; |
322 | 332 | } |
323 | 333 | |
@@ -341,16 +351,18 @@ discard block |
||
341 | 351 | { |
342 | 352 | $base = $this->getErrorTemplatePath() . DIRECTORY_SEPARATOR . self::ERROR_FILE_NAME; |
343 | 353 | $lang = Prado::getPreferredLanguage(); |
344 | - if(is_file("$base$statusCode-$lang.html")) |
|
345 | - $errorFile = "$base$statusCode-$lang.html"; |
|
346 | - elseif(is_file("$base$statusCode.html")) |
|
347 | - $errorFile = "$base$statusCode.html"; |
|
348 | - elseif(is_file("$base-$lang.html")) |
|
349 | - $errorFile = "$base-$lang.html"; |
|
350 | - else |
|
351 | - $errorFile = "$base.html"; |
|
352 | - if(($content = @file_get_contents($errorFile)) === false) |
|
353 | - die("Unable to open error template file '$errorFile'."); |
|
354 | + if(is_file("$base$statusCode-$lang.html")) { |
|
355 | + $errorFile = "$base$statusCode-$lang.html"; |
|
356 | + } elseif(is_file("$base$statusCode.html")) { |
|
357 | + $errorFile = "$base$statusCode.html"; |
|
358 | + } elseif(is_file("$base-$lang.html")) { |
|
359 | + $errorFile = "$base-$lang.html"; |
|
360 | + } else { |
|
361 | + $errorFile = "$base.html"; |
|
362 | + } |
|
363 | + if(($content = @file_get_contents($errorFile)) === false) { |
|
364 | + die("Unable to open error template file '$errorFile'."); |
|
365 | + } |
|
354 | 366 | return $content; |
355 | 367 | } |
356 | 368 | |
@@ -368,17 +380,20 @@ discard block |
||
368 | 380 | // if PHP exception, we want to show the 2nd stack level context |
369 | 381 | // because the 1st stack level is of little use (it's in error handler) |
370 | 382 | if($exception instanceof TPhpErrorException) { |
371 | - if(isset($trace[0]['file'])) |
|
372 | - $result = $trace[0]; |
|
373 | - elseif(isset($trace[1])) |
|
374 | - $result = $trace[1]; |
|
383 | + if(isset($trace[0]['file'])) { |
|
384 | + $result = $trace[0]; |
|
385 | + } elseif(isset($trace[1])) { |
|
386 | + $result = $trace[1]; |
|
387 | + } |
|
375 | 388 | } elseif($exception instanceof TInvalidOperationException) { |
376 | 389 | // in case of getter or setter error, find out the exact file and row |
377 | - if(($result = $this->getPropertyAccessTrace($trace, '__get')) === null) |
|
378 | - $result = $this->getPropertyAccessTrace($trace, '__set'); |
|
390 | + if(($result = $this->getPropertyAccessTrace($trace, '__get')) === null) { |
|
391 | + $result = $this->getPropertyAccessTrace($trace, '__set'); |
|
392 | + } |
|
393 | + } |
|
394 | + if($result !== null && strpos($result['file'], ': eval()\'d code') !== false) { |
|
395 | + return null; |
|
379 | 396 | } |
380 | - if($result !== null && strpos($result['file'], ': eval()\'d code') !== false) |
|
381 | - return null; |
|
382 | 397 | |
383 | 398 | return $result; |
384 | 399 | } |
@@ -395,10 +410,11 @@ discard block |
||
395 | 410 | // try to mimic Exception::getTraceAsString() |
396 | 411 | foreach($trace as $line) |
397 | 412 | { |
398 | - if(array_key_exists('function', $line)) |
|
399 | - $func = $line['function'] . '(' . implode(',', $line['params']) . ')'; |
|
400 | - else |
|
401 | - $func = 'unknown'; |
|
413 | + if(array_key_exists('function', $line)) { |
|
414 | + $func = $line['function'] . '(' . implode(',', $line['params']) . ')'; |
|
415 | + } else { |
|
416 | + $func = 'unknown'; |
|
417 | + } |
|
402 | 418 | |
403 | 419 | $txt .= '#' . $row . ' ' . $line['file'] . '(' . $line['line'] . '): ' . $func . "\n"; |
404 | 420 | $row++; |
@@ -415,10 +431,11 @@ discard block |
||
415 | 431 | $result = null; |
416 | 432 | foreach($trace as $t) |
417 | 433 | { |
418 | - if(isset($t['function']) && $t['function'] === $pattern) |
|
419 | - $result = $t; |
|
420 | - else |
|
421 | - break; |
|
434 | + if(isset($t['function']) && $t['function'] === $pattern) { |
|
435 | + $result = $t; |
|
436 | + } else { |
|
437 | + break; |
|
438 | + } |
|
422 | 439 | } |
423 | 440 | return $result; |
424 | 441 | } |
@@ -435,9 +452,9 @@ discard block |
||
435 | 452 | { |
436 | 453 | $line = htmlspecialchars(sprintf("%04d: %s", $i + 1, str_replace("\t", ' ', $lines[$i]))); |
437 | 454 | $source .= "<div class=\"error\">" . $line . "</div>"; |
455 | + } else { |
|
456 | + $source .= htmlspecialchars(sprintf("%04d: %s", $i + 1, str_replace("\t", ' ', $lines[$i]))); |
|
438 | 457 | } |
439 | - else |
|
440 | - $source .= htmlspecialchars(sprintf("%04d: %s", $i + 1, str_replace("\t", ' ', $lines[$i]))); |
|
441 | 458 | } |
442 | 459 | return $source; |
443 | 460 | } |
@@ -456,8 +473,7 @@ discard block |
||
456 | 473 | $class = $matches[0]; |
457 | 474 | try { |
458 | 475 | $function = new \ReflectionClass($class); |
459 | - } |
|
460 | - catch (\Exception $e) { |
|
476 | + } catch (\Exception $e) { |
|
461 | 477 | return null; |
462 | 478 | } |
463 | 479 | $classname = $function->getNamespaceName(); |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | */ |
44 | 44 | protected function getStateFilePath() |
45 | 45 | { |
46 | - return $this->getApplication()->getRuntimePath() . '/global.cache'; |
|
46 | + return $this->getApplication()->getRuntimePath().'/global.cache'; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -52,11 +52,11 @@ discard block |
||
52 | 52 | */ |
53 | 53 | public function load() |
54 | 54 | { |
55 | - if(($cache = $this->getApplication()->getCache()) !== null && ($value = $cache->get(self::CACHE_NAME)) !== false) |
|
55 | + if (($cache = $this->getApplication()->getCache()) !== null && ($value = $cache->get(self::CACHE_NAME)) !== false) |
|
56 | 56 | return unserialize($value); |
57 | 57 | else |
58 | 58 | { |
59 | - if(($content = @file_get_contents($this->getStateFilePath())) !== false) |
|
59 | + if (($content = @file_get_contents($this->getStateFilePath())) !== false) |
|
60 | 60 | return unserialize($content); |
61 | 61 | else |
62 | 62 | return null; |
@@ -71,14 +71,14 @@ discard block |
||
71 | 71 | { |
72 | 72 | $content = serialize($state); |
73 | 73 | $saveFile = true; |
74 | - if(($cache = $this->getApplication()->getCache()) !== null) |
|
74 | + if (($cache = $this->getApplication()->getCache()) !== null) |
|
75 | 75 | { |
76 | - if($cache->get(self::CACHE_NAME) === $content) |
|
76 | + if ($cache->get(self::CACHE_NAME) === $content) |
|
77 | 77 | $saveFile = false; |
78 | 78 | else |
79 | 79 | $cache->set(self::CACHE_NAME, $content); |
80 | 80 | } |
81 | - if($saveFile) |
|
81 | + if ($saveFile) |
|
82 | 82 | { |
83 | 83 | $fileName = $this->getStateFilePath(); |
84 | 84 | file_put_contents($fileName, $content, LOCK_EX); |
@@ -52,14 +52,15 @@ discard block |
||
52 | 52 | */ |
53 | 53 | public function load() |
54 | 54 | { |
55 | - if(($cache = $this->getApplication()->getCache()) !== null && ($value = $cache->get(self::CACHE_NAME)) !== false) |
|
56 | - return unserialize($value); |
|
57 | - else |
|
55 | + if(($cache = $this->getApplication()->getCache()) !== null && ($value = $cache->get(self::CACHE_NAME)) !== false) { |
|
56 | + return unserialize($value); |
|
57 | + } else |
|
58 | 58 | { |
59 | - if(($content = @file_get_contents($this->getStateFilePath())) !== false) |
|
60 | - return unserialize($content); |
|
61 | - else |
|
62 | - return null; |
|
59 | + if(($content = @file_get_contents($this->getStateFilePath())) !== false) { |
|
60 | + return unserialize($content); |
|
61 | + } else { |
|
62 | + return null; |
|
63 | + } |
|
63 | 64 | } |
64 | 65 | } |
65 | 66 | |
@@ -73,10 +74,11 @@ discard block |
||
73 | 74 | $saveFile = true; |
74 | 75 | if(($cache = $this->getApplication()->getCache()) !== null) |
75 | 76 | { |
76 | - if($cache->get(self::CACHE_NAME) === $content) |
|
77 | - $saveFile = false; |
|
78 | - else |
|
79 | - $cache->set(self::CACHE_NAME, $content); |
|
77 | + if($cache->get(self::CACHE_NAME) === $content) { |
|
78 | + $saveFile = false; |
|
79 | + } else { |
|
80 | + $cache->set(self::CACHE_NAME, $content); |
|
81 | + } |
|
80 | 82 | } |
81 | 83 | if($saveFile) |
82 | 84 | { |
@@ -105,7 +105,7 @@ |
||
105 | 105 | $choice = new ChoiceFormat(); |
106 | 106 | $value = $this->getValue(); |
107 | 107 | $string = $choice->format($text, $value); |
108 | - if($string) |
|
108 | + if ($string) |
|
109 | 109 | return strtr($string, ['{Value}' => $value]); |
110 | 110 | } |
111 | 111 | } |
@@ -105,7 +105,8 @@ |
||
105 | 105 | $choice = new ChoiceFormat(); |
106 | 106 | $value = $this->getValue(); |
107 | 107 | $string = $choice->format($text, $value); |
108 | - if($string) |
|
109 | - return strtr($string, ['{Value}' => $value]); |
|
108 | + if($string) { |
|
109 | + return strtr($string, ['{Value}' => $value]); |
|
110 | + } |
|
110 | 111 | } |
111 | 112 | } |