@@ -37,42 +37,42 @@ discard block |
||
37 | 37 | const TYPE_PHONE = 'phone'; |
38 | 38 | const TYPE_URL = 'url'; |
39 | 39 | |
40 | - /** |
|
41 | - * The original URL that was passed to the constructor. |
|
42 | - * @var string |
|
43 | - */ |
|
40 | + /** |
|
41 | + * The original URL that was passed to the constructor. |
|
42 | + * @var string |
|
43 | + */ |
|
44 | 44 | protected $rawURL; |
45 | 45 | |
46 | - /** |
|
47 | - * @var array |
|
48 | - */ |
|
46 | + /** |
|
47 | + * @var array |
|
48 | + */ |
|
49 | 49 | protected $info; |
50 | 50 | |
51 | - /** |
|
52 | - * @var string[] |
|
53 | - */ |
|
51 | + /** |
|
52 | + * @var string[] |
|
53 | + */ |
|
54 | 54 | protected $excludedParams = array(); |
55 | 55 | |
56 | - /** |
|
57 | - * @var bool |
|
58 | - * @see URLInfo::setParamExclusion() |
|
59 | - */ |
|
56 | + /** |
|
57 | + * @var bool |
|
58 | + * @see URLInfo::setParamExclusion() |
|
59 | + */ |
|
60 | 60 | protected $paramExclusion = false; |
61 | 61 | |
62 | - /** |
|
63 | - * @var array |
|
64 | - * @see URLInfo::getTypeLabel() |
|
65 | - */ |
|
62 | + /** |
|
63 | + * @var array |
|
64 | + * @see URLInfo::getTypeLabel() |
|
65 | + */ |
|
66 | 66 | protected static $typeLabels; |
67 | 67 | |
68 | - /** |
|
69 | - * @var bool |
|
70 | - */ |
|
68 | + /** |
|
69 | + * @var bool |
|
70 | + */ |
|
71 | 71 | protected $highlightExcluded = false; |
72 | 72 | |
73 | - /** |
|
74 | - * @var array |
|
75 | - */ |
|
73 | + /** |
|
74 | + * @var array |
|
75 | + */ |
|
76 | 76 | protected $infoKeys = array( |
77 | 77 | 'scheme', |
78 | 78 | 'host', |
@@ -84,19 +84,19 @@ discard block |
||
84 | 84 | 'fragment' |
85 | 85 | ); |
86 | 86 | |
87 | - /** |
|
88 | - * @var string |
|
89 | - */ |
|
87 | + /** |
|
88 | + * @var string |
|
89 | + */ |
|
90 | 90 | protected $url; |
91 | 91 | |
92 | - /** |
|
93 | - * @var URLInfo_Parser |
|
94 | - */ |
|
92 | + /** |
|
93 | + * @var URLInfo_Parser |
|
94 | + */ |
|
95 | 95 | protected $parser; |
96 | 96 | |
97 | - /** |
|
98 | - * @var URLInfo_Normalizer |
|
99 | - */ |
|
97 | + /** |
|
98 | + * @var URLInfo_Normalizer |
|
99 | + */ |
|
100 | 100 | protected $normalizer; |
101 | 101 | |
102 | 102 | public function __construct(string $url) |
@@ -108,13 +108,13 @@ discard block |
||
108 | 108 | $this->info = $this->parser->getInfo(); |
109 | 109 | } |
110 | 110 | |
111 | - /** |
|
112 | - * Filters an URL: removes control characters and the |
|
113 | - * like to have a clean URL to work with. |
|
114 | - * |
|
115 | - * @param string $url |
|
116 | - * @return string |
|
117 | - */ |
|
111 | + /** |
|
112 | + * Filters an URL: removes control characters and the |
|
113 | + * like to have a clean URL to work with. |
|
114 | + * |
|
115 | + * @param string $url |
|
116 | + * @return string |
|
117 | + */ |
|
118 | 118 | public static function filterURL(string $url) |
119 | 119 | { |
120 | 120 | return URLInfo_Filter::filter($url); |
@@ -144,12 +144,12 @@ discard block |
||
144 | 144 | return $this->info['type'] === self::TYPE_PHONE; |
145 | 145 | } |
146 | 146 | |
147 | - /** |
|
148 | - * Whether the URL is a regular URL, not one of the |
|
149 | - * other types like a phone number or email address. |
|
150 | - * |
|
151 | - * @return bool |
|
152 | - */ |
|
147 | + /** |
|
148 | + * Whether the URL is a regular URL, not one of the |
|
149 | + * other types like a phone number or email address. |
|
150 | + * |
|
151 | + * @return bool |
|
152 | + */ |
|
153 | 153 | public function isURL() : bool |
154 | 154 | { |
155 | 155 | $host = $this->getHost(); |
@@ -161,20 +161,20 @@ discard block |
||
161 | 161 | return $this->parser->isValid(); |
162 | 162 | } |
163 | 163 | |
164 | - /** |
|
165 | - * Retrieves the host name, or an empty string if none is present. |
|
166 | - * |
|
167 | - * @return string |
|
168 | - */ |
|
164 | + /** |
|
165 | + * Retrieves the host name, or an empty string if none is present. |
|
166 | + * |
|
167 | + * @return string |
|
168 | + */ |
|
169 | 169 | public function getHost() : string |
170 | 170 | { |
171 | 171 | return $this->getInfoKey('host'); |
172 | 172 | } |
173 | 173 | |
174 | - /** |
|
175 | - * Retrieves the path, or an empty string if none is present. |
|
176 | - * @return string |
|
177 | - */ |
|
174 | + /** |
|
175 | + * Retrieves the path, or an empty string if none is present. |
|
176 | + * @return string |
|
177 | + */ |
|
178 | 178 | public function getPath() : string |
179 | 179 | { |
180 | 180 | return $this->getInfoKey('path'); |
@@ -190,10 +190,10 @@ discard block |
||
190 | 190 | return $this->getInfoKey('scheme'); |
191 | 191 | } |
192 | 192 | |
193 | - /** |
|
194 | - * Retrieves the port specified in the URL, or -1 if none is preseent. |
|
195 | - * @return int |
|
196 | - */ |
|
193 | + /** |
|
194 | + * Retrieves the port specified in the URL, or -1 if none is preseent. |
|
195 | + * @return int |
|
196 | + */ |
|
197 | 197 | public function getPort() : int |
198 | 198 | { |
199 | 199 | $port = $this->getInfoKey('port'); |
@@ -205,13 +205,13 @@ discard block |
||
205 | 205 | return -1; |
206 | 206 | } |
207 | 207 | |
208 | - /** |
|
209 | - * Retrieves the raw query string, or an empty string if none is present. |
|
210 | - * |
|
211 | - * @return string |
|
212 | - * |
|
213 | - * @see URLInfo::getParams() |
|
214 | - */ |
|
208 | + /** |
|
209 | + * Retrieves the raw query string, or an empty string if none is present. |
|
210 | + * |
|
211 | + * @return string |
|
212 | + * |
|
213 | + * @see URLInfo::getParams() |
|
214 | + */ |
|
215 | 215 | public function getQuery() : string |
216 | 216 | { |
217 | 217 | return $this->getInfoKey('query'); |
@@ -227,20 +227,20 @@ discard block |
||
227 | 227 | return $this->getInfoKey('pass'); |
228 | 228 | } |
229 | 229 | |
230 | - /** |
|
231 | - * Whether the URL contains a port number. |
|
232 | - * @return bool |
|
233 | - */ |
|
230 | + /** |
|
231 | + * Whether the URL contains a port number. |
|
232 | + * @return bool |
|
233 | + */ |
|
234 | 234 | public function hasPort() : bool |
235 | 235 | { |
236 | 236 | return $this->getPort() !== -1; |
237 | 237 | } |
238 | 238 | |
239 | - /** |
|
240 | - * Alias for the hasParams() method. |
|
241 | - * @return bool |
|
242 | - * @see URLInfo::hasParams() |
|
243 | - */ |
|
239 | + /** |
|
240 | + * Alias for the hasParams() method. |
|
241 | + * @return bool |
|
242 | + * @see URLInfo::hasParams() |
|
243 | + */ |
|
244 | 244 | public function hasQuery() : bool |
245 | 245 | { |
246 | 246 | return $this->hasParams(); |
@@ -298,25 +298,25 @@ discard block |
||
298 | 298 | return $this->normalizer->normalize(); |
299 | 299 | } |
300 | 300 | |
301 | - /** |
|
302 | - * Creates a hash of the URL, which can be used for comparisons. |
|
303 | - * Since any parameters in the URL's query are sorted alphabetically, |
|
304 | - * the same links with a different parameter order will have the |
|
305 | - * same hash. |
|
306 | - * |
|
307 | - * @return string |
|
308 | - */ |
|
301 | + /** |
|
302 | + * Creates a hash of the URL, which can be used for comparisons. |
|
303 | + * Since any parameters in the URL's query are sorted alphabetically, |
|
304 | + * the same links with a different parameter order will have the |
|
305 | + * same hash. |
|
306 | + * |
|
307 | + * @return string |
|
308 | + */ |
|
309 | 309 | public function getHash() |
310 | 310 | { |
311 | 311 | return \AppUtils\ConvertHelper::string2shortHash($this->getNormalized()); |
312 | 312 | } |
313 | 313 | |
314 | - /** |
|
315 | - * Highlights the URL using HTML tags with specific highlighting |
|
316 | - * class names. |
|
317 | - * |
|
318 | - * @return string Will return an empty string if the URL is not valid. |
|
319 | - */ |
|
314 | + /** |
|
315 | + * Highlights the URL using HTML tags with specific highlighting |
|
316 | + * class names. |
|
317 | + * |
|
318 | + * @return string Will return an empty string if the URL is not valid. |
|
319 | + */ |
|
320 | 320 | public function getHighlighted() : string |
321 | 321 | { |
322 | 322 | if(!$this->isValid()) { |
@@ -350,15 +350,15 @@ discard block |
||
350 | 350 | return count($params); |
351 | 351 | } |
352 | 352 | |
353 | - /** |
|
354 | - * Retrieves all parameters specified in the url, |
|
355 | - * if any, as an associative array. |
|
356 | - * |
|
357 | - * NOTE: Ignores parameters that have been added |
|
358 | - * to the excluded parameters list. |
|
359 | - * |
|
360 | - * @return array |
|
361 | - */ |
|
353 | + /** |
|
354 | + * Retrieves all parameters specified in the url, |
|
355 | + * if any, as an associative array. |
|
356 | + * |
|
357 | + * NOTE: Ignores parameters that have been added |
|
358 | + * to the excluded parameters list. |
|
359 | + * |
|
360 | + * @return array |
|
361 | + */ |
|
362 | 362 | public function getParams() : array |
363 | 363 | { |
364 | 364 | if(!$this->paramExclusion || empty($this->excludedParams)) { |
@@ -376,22 +376,22 @@ discard block |
||
376 | 376 | return $keep; |
377 | 377 | } |
378 | 378 | |
379 | - /** |
|
380 | - * Retrieves the names of all parameters present in the URL, if any. |
|
381 | - * @return string[] |
|
382 | - */ |
|
379 | + /** |
|
380 | + * Retrieves the names of all parameters present in the URL, if any. |
|
381 | + * @return string[] |
|
382 | + */ |
|
383 | 383 | public function getParamNames() : array |
384 | 384 | { |
385 | 385 | $params = $this->getParams(); |
386 | 386 | return array_keys($params); |
387 | 387 | } |
388 | 388 | |
389 | - /** |
|
390 | - * Retrieves a specific parameter value from the URL. |
|
391 | - * |
|
392 | - * @param string $name |
|
393 | - * @return string The parameter value, or an empty string if it does not exist. |
|
394 | - */ |
|
389 | + /** |
|
390 | + * Retrieves a specific parameter value from the URL. |
|
391 | + * |
|
392 | + * @param string $name |
|
393 | + * @return string The parameter value, or an empty string if it does not exist. |
|
394 | + */ |
|
395 | 395 | public function getParam(string $name) : string |
396 | 396 | { |
397 | 397 | if(isset($this->info['params'][$name])) { |
@@ -401,16 +401,16 @@ discard block |
||
401 | 401 | return ''; |
402 | 402 | } |
403 | 403 | |
404 | - /** |
|
405 | - * Excludes an URL parameter entirely if present: |
|
406 | - * the parser will act as if the parameter was not |
|
407 | - * even present in the source URL, effectively |
|
408 | - * stripping it. |
|
409 | - * |
|
410 | - * @param string $name |
|
411 | - * @param string $reason A human readable explanation why this is excluded - used when highlighting links. |
|
412 | - * @return URLInfo |
|
413 | - */ |
|
404 | + /** |
|
405 | + * Excludes an URL parameter entirely if present: |
|
406 | + * the parser will act as if the parameter was not |
|
407 | + * even present in the source URL, effectively |
|
408 | + * stripping it. |
|
409 | + * |
|
410 | + * @param string $name |
|
411 | + * @param string $reason A human readable explanation why this is excluded - used when highlighting links. |
|
412 | + * @return URLInfo |
|
413 | + */ |
|
414 | 414 | public function excludeParam(string $name, string $reason) : URLInfo |
415 | 415 | { |
416 | 416 | if(!isset($this->excludedParams[$name])) |
@@ -463,25 +463,25 @@ discard block |
||
463 | 463 | return self::$typeLabels[$this->getType()]; |
464 | 464 | } |
465 | 465 | |
466 | - /** |
|
467 | - * Whether excluded parameters should be highlighted in |
|
468 | - * a different color in the URL when using the |
|
469 | - * {@link URLInfo::getHighlighted()} method. |
|
470 | - * |
|
471 | - * @param bool $highlight |
|
472 | - * @return URLInfo |
|
473 | - */ |
|
466 | + /** |
|
467 | + * Whether excluded parameters should be highlighted in |
|
468 | + * a different color in the URL when using the |
|
469 | + * {@link URLInfo::getHighlighted()} method. |
|
470 | + * |
|
471 | + * @param bool $highlight |
|
472 | + * @return URLInfo |
|
473 | + */ |
|
474 | 474 | public function setHighlightExcluded(bool $highlight=true) : URLInfo |
475 | 475 | { |
476 | 476 | $this->highlightExcluded = $highlight; |
477 | 477 | return $this; |
478 | 478 | } |
479 | 479 | |
480 | - /** |
|
481 | - * Returns an array with all relevant URL information. |
|
482 | - * |
|
483 | - * @return array |
|
484 | - */ |
|
480 | + /** |
|
481 | + * Returns an array with all relevant URL information. |
|
482 | + * |
|
483 | + * @return array |
|
484 | + */ |
|
485 | 485 | public function toArray() : array |
486 | 486 | { |
487 | 487 | return array( |
@@ -525,24 +525,24 @@ discard block |
||
525 | 525 | return $this; |
526 | 526 | } |
527 | 527 | |
528 | - /** |
|
529 | - * Whether the parameter exclusion mode is enabled: |
|
530 | - * In this case, if any parameters have been added to the |
|
531 | - * exclusion list, all relevant methods will exclude these. |
|
532 | - * |
|
533 | - * @return bool |
|
534 | - */ |
|
528 | + /** |
|
529 | + * Whether the parameter exclusion mode is enabled: |
|
530 | + * In this case, if any parameters have been added to the |
|
531 | + * exclusion list, all relevant methods will exclude these. |
|
532 | + * |
|
533 | + * @return bool |
|
534 | + */ |
|
535 | 535 | public function isParamExclusionEnabled() : bool |
536 | 536 | { |
537 | 537 | return $this->paramExclusion; |
538 | 538 | } |
539 | 539 | |
540 | - /** |
|
541 | - * Checks whether the link contains any parameters that |
|
542 | - * are on the list of excluded parameters. |
|
543 | - * |
|
544 | - * @return bool |
|
545 | - */ |
|
540 | + /** |
|
541 | + * Checks whether the link contains any parameters that |
|
542 | + * are on the list of excluded parameters. |
|
543 | + * |
|
544 | + * @return bool |
|
545 | + */ |
|
546 | 546 | public function containsExcludedParams() : bool |
547 | 547 | { |
548 | 548 | if(empty($this->excludedParams)) { |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | { |
199 | 199 | $port = $this->getInfoKey('port'); |
200 | 200 | |
201 | - if(!empty($port)) { |
|
201 | + if (!empty($port)) { |
|
202 | 202 | return (int)$port; |
203 | 203 | } |
204 | 204 | |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | |
279 | 279 | protected function getInfoKey(string $name) : string |
280 | 280 | { |
281 | - if(isset($this->info[$name])) { |
|
281 | + if (isset($this->info[$name])) { |
|
282 | 282 | return (string)$this->info[$name]; |
283 | 283 | } |
284 | 284 | |
@@ -287,11 +287,11 @@ discard block |
||
287 | 287 | |
288 | 288 | public function getNormalized() : string |
289 | 289 | { |
290 | - if(!$this->isValid()) { |
|
290 | + if (!$this->isValid()) { |
|
291 | 291 | return ''; |
292 | 292 | } |
293 | 293 | |
294 | - if(!isset($this->normalizer)) { |
|
294 | + if (!isset($this->normalizer)) { |
|
295 | 295 | $this->normalizer = new URLInfo_Normalizer($this); |
296 | 296 | } |
297 | 297 | |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | */ |
320 | 320 | public function getHighlighted() : string |
321 | 321 | { |
322 | - if(!$this->isValid()) { |
|
322 | + if (!$this->isValid()) { |
|
323 | 323 | return ''; |
324 | 324 | } |
325 | 325 | |
@@ -361,14 +361,14 @@ discard block |
||
361 | 361 | */ |
362 | 362 | public function getParams() : array |
363 | 363 | { |
364 | - if(!$this->paramExclusion || empty($this->excludedParams)) { |
|
364 | + if (!$this->paramExclusion || empty($this->excludedParams)) { |
|
365 | 365 | return $this->info['params']; |
366 | 366 | } |
367 | 367 | |
368 | 368 | $keep = array(); |
369 | - foreach($this->info['params'] as $name => $value) |
|
369 | + foreach ($this->info['params'] as $name => $value) |
|
370 | 370 | { |
371 | - if(!isset($this->excludedParams[$name])) { |
|
371 | + if (!isset($this->excludedParams[$name])) { |
|
372 | 372 | $keep[$name] = $value; |
373 | 373 | } |
374 | 374 | } |
@@ -394,7 +394,7 @@ discard block |
||
394 | 394 | */ |
395 | 395 | public function getParam(string $name) : string |
396 | 396 | { |
397 | - if(isset($this->info['params'][$name])) { |
|
397 | + if (isset($this->info['params'][$name])) { |
|
398 | 398 | return $this->info['params'][$name]; |
399 | 399 | } |
400 | 400 | |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | */ |
414 | 414 | public function excludeParam(string $name, string $reason) : URLInfo |
415 | 415 | { |
416 | - if(!isset($this->excludedParams[$name])) |
|
416 | + if (!isset($this->excludedParams[$name])) |
|
417 | 417 | { |
418 | 418 | $this->excludedParams[$name] = $reason; |
419 | 419 | $this->setParamExclusion(); |
@@ -439,7 +439,7 @@ discard block |
||
439 | 439 | |
440 | 440 | public function getTypeLabel() : string |
441 | 441 | { |
442 | - if(!isset(self::$typeLabels)) |
|
442 | + if (!isset(self::$typeLabels)) |
|
443 | 443 | { |
444 | 444 | self::$typeLabels = array( |
445 | 445 | self::TYPE_EMAIL => t('Email'), |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | |
452 | 452 | $type = $this->getType(); |
453 | 453 | |
454 | - if(!isset(self::$typeLabels[$type])) |
|
454 | + if (!isset(self::$typeLabels[$type])) |
|
455 | 455 | { |
456 | 456 | throw new BaseException( |
457 | 457 | sprintf('Unknown URL type label for type [%s].', $type), |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | * @param bool $highlight |
472 | 472 | * @return URLInfo |
473 | 473 | */ |
474 | - public function setHighlightExcluded(bool $highlight=true) : URLInfo |
|
474 | + public function setHighlightExcluded(bool $highlight = true) : URLInfo |
|
475 | 475 | { |
476 | 476 | $this->highlightExcluded = $highlight; |
477 | 477 | return $this; |
@@ -519,7 +519,7 @@ discard block |
||
519 | 519 | * @see URLInfo::isParamExclusionEnabled() |
520 | 520 | * @see URLInfo::setHighlightExcluded() |
521 | 521 | */ |
522 | - public function setParamExclusion(bool $enabled=true) : URLInfo |
|
522 | + public function setParamExclusion(bool $enabled = true) : URLInfo |
|
523 | 523 | { |
524 | 524 | $this->paramExclusion = $enabled; |
525 | 525 | return $this; |
@@ -545,13 +545,13 @@ discard block |
||
545 | 545 | */ |
546 | 546 | public function containsExcludedParams() : bool |
547 | 547 | { |
548 | - if(empty($this->excludedParams)) { |
|
548 | + if (empty($this->excludedParams)) { |
|
549 | 549 | return false; |
550 | 550 | } |
551 | 551 | |
552 | 552 | $names = array_keys($this->info['params']); |
553 | - foreach($names as $name) { |
|
554 | - if(isset($this->excludedParams[$name])) { |
|
553 | + foreach ($names as $name) { |
|
554 | + if (isset($this->excludedParams[$name])) { |
|
555 | 555 | return true; |
556 | 556 | } |
557 | 557 | } |
@@ -567,7 +567,7 @@ discard block |
||
567 | 567 | |
568 | 568 | public function offsetSet($offset, $value) |
569 | 569 | { |
570 | - if(in_array($offset, $this->infoKeys)) { |
|
570 | + if (in_array($offset, $this->infoKeys)) { |
|
571 | 571 | $this->info[$offset] = $value; |
572 | 572 | } |
573 | 573 | } |
@@ -584,11 +584,11 @@ discard block |
||
584 | 584 | |
585 | 585 | public function offsetGet($offset) |
586 | 586 | { |
587 | - if($offset === 'port') { |
|
587 | + if ($offset === 'port') { |
|
588 | 588 | return $this->getPort(); |
589 | 589 | } |
590 | 590 | |
591 | - if(in_array($offset, $this->infoKeys)) { |
|
591 | + if (in_array($offset, $this->infoKeys)) { |
|
592 | 592 | return $this->getInfoKey($offset); |
593 | 593 | } |
594 | 594 |
@@ -56,16 +56,16 @@ |
||
56 | 56 | { |
57 | 57 | $normalized = $this->info->getScheme().'://'.$this->info->getHost(); |
58 | 58 | |
59 | - if($this->info->hasPath()) { |
|
59 | + if ($this->info->hasPath()) { |
|
60 | 60 | $normalized .= $this->info->getPath(); |
61 | 61 | } |
62 | 62 | |
63 | 63 | $params = $this->info->getParams(); |
64 | - if(!empty($params)) { |
|
64 | + if (!empty($params)) { |
|
65 | 65 | $normalized .= '?'.http_build_query($params); |
66 | 66 | } |
67 | 67 | |
68 | - if($this->info->hasFragment()) { |
|
68 | + if ($this->info->hasFragment()) { |
|
69 | 69 | $normalized .= '#'.$this->info->getFragment(); |
70 | 70 | } |
71 | 71 |
@@ -39,9 +39,9 @@ discard block |
||
39 | 39 | */ |
40 | 40 | protected static $instance; |
41 | 41 | |
42 | - /** |
|
43 | - * @var string |
|
44 | - */ |
|
42 | + /** |
|
43 | + * @var string |
|
44 | + */ |
|
45 | 45 | protected $baseURL = ''; |
46 | 46 | |
47 | 47 | public function __construct() |
@@ -51,10 +51,10 @@ discard block |
||
51 | 51 | $this->init(); |
52 | 52 | } |
53 | 53 | |
54 | - /** |
|
55 | - * Can be extended in a subclass, to avoid |
|
56 | - * redefining the constructor. |
|
57 | - */ |
|
54 | + /** |
|
55 | + * Can be extended in a subclass, to avoid |
|
56 | + * redefining the constructor. |
|
57 | + */ |
|
58 | 58 | protected function init() |
59 | 59 | { |
60 | 60 | |
@@ -124,12 +124,12 @@ discard block |
||
124 | 124 | return $this->buildURL($params, $dispatcher); |
125 | 125 | } |
126 | 126 | |
127 | - /** |
|
128 | - * Retrieves the name of the current dispatcher script / page. |
|
129 | - * This is made to be extended and implemented in a subclass. |
|
130 | - * |
|
131 | - * @return string |
|
132 | - */ |
|
127 | + /** |
|
128 | + * Retrieves the name of the current dispatcher script / page. |
|
129 | + * This is made to be extended and implemented in a subclass. |
|
130 | + * |
|
131 | + * @return string |
|
132 | + */ |
|
133 | 133 | public function getDispatcher() : string |
134 | 134 | { |
135 | 135 | return ''; |
@@ -198,10 +198,10 @@ discard block |
||
198 | 198 | return $url; |
199 | 199 | } |
200 | 200 | |
201 | - /** |
|
202 | - * Retrieves the base URL of the application. |
|
203 | - * @return string |
|
204 | - */ |
|
201 | + /** |
|
202 | + * Retrieves the base URL of the application. |
|
203 | + * @return string |
|
204 | + */ |
|
205 | 205 | public function getBaseURL() : string |
206 | 206 | { |
207 | 207 | return $this->baseURL; |
@@ -231,13 +231,13 @@ discard block |
||
231 | 231 | return $this->knownParams[$name]; |
232 | 232 | } |
233 | 233 | |
234 | - /** |
|
235 | - * Retrieves a previously registered parameter instance. |
|
236 | - * |
|
237 | - * @param string $name |
|
238 | - * @throws Request_Exception |
|
239 | - * @return Request_Param |
|
240 | - */ |
|
234 | + /** |
|
235 | + * Retrieves a previously registered parameter instance. |
|
236 | + * |
|
237 | + * @param string $name |
|
238 | + * @throws Request_Exception |
|
239 | + * @return Request_Param |
|
240 | + */ |
|
241 | 241 | public function getRegisteredParam(string $name) : Request_Param |
242 | 242 | { |
243 | 243 | if(isset($this->knownParams[$name])) { |
@@ -254,48 +254,48 @@ discard block |
||
254 | 254 | ); |
255 | 255 | } |
256 | 256 | |
257 | - /** |
|
258 | - * Checks whether a parameter with the specified name |
|
259 | - * has been registered. |
|
260 | - * |
|
261 | - * @param string $name |
|
262 | - * @return bool |
|
263 | - */ |
|
257 | + /** |
|
258 | + * Checks whether a parameter with the specified name |
|
259 | + * has been registered. |
|
260 | + * |
|
261 | + * @param string $name |
|
262 | + * @return bool |
|
263 | + */ |
|
264 | 264 | public function hasRegisteredParam(string $name) : bool |
265 | 265 | { |
266 | 266 | return isset($this->knownParams[$name]); |
267 | 267 | } |
268 | 268 | |
269 | - /** |
|
270 | - * Retrieves an indexed array with accept mime types |
|
271 | - * that the client sent, in the order of preference |
|
272 | - * the client specified. |
|
273 | - * |
|
274 | - * Example: |
|
275 | - * |
|
276 | - * array( |
|
277 | - * 'text/html', |
|
278 | - * 'application/xhtml+xml', |
|
279 | - * 'image/webp' |
|
280 | - * ... |
|
281 | - * ) |
|
282 | - * |
|
283 | - * @return array |
|
284 | - * @see Request::parseAcceptHeaders() |
|
285 | - */ |
|
269 | + /** |
|
270 | + * Retrieves an indexed array with accept mime types |
|
271 | + * that the client sent, in the order of preference |
|
272 | + * the client specified. |
|
273 | + * |
|
274 | + * Example: |
|
275 | + * |
|
276 | + * array( |
|
277 | + * 'text/html', |
|
278 | + * 'application/xhtml+xml', |
|
279 | + * 'image/webp' |
|
280 | + * ... |
|
281 | + * ) |
|
282 | + * |
|
283 | + * @return array |
|
284 | + * @see Request::parseAcceptHeaders() |
|
285 | + */ |
|
286 | 286 | public static function getAcceptHeaders() : array |
287 | 287 | { |
288 | 288 | return self::parseAcceptHeaders()->getMimeStrings(); |
289 | 289 | } |
290 | 290 | |
291 | - /** |
|
292 | - * Returns an instance of the accept headers parser, |
|
293 | - * to access information on the browser's accepted |
|
294 | - * mime types. |
|
295 | - * |
|
296 | - * @return Request_AcceptHeaders |
|
297 | - * @see Request::getAcceptHeaders() |
|
298 | - */ |
|
291 | + /** |
|
292 | + * Returns an instance of the accept headers parser, |
|
293 | + * to access information on the browser's accepted |
|
294 | + * mime types. |
|
295 | + * |
|
296 | + * @return Request_AcceptHeaders |
|
297 | + * @see Request::getAcceptHeaders() |
|
298 | + */ |
|
299 | 299 | public static function parseAcceptHeaders() : Request_AcceptHeaders |
300 | 300 | { |
301 | 301 | static $accept; |
@@ -343,14 +343,14 @@ discard block |
||
343 | 343 | return false; |
344 | 344 | } |
345 | 345 | |
346 | - /** |
|
347 | - * Removes a single parameter from the request. |
|
348 | - * If the parameter has been registered, also |
|
349 | - * removes the registration info. |
|
350 | - * |
|
351 | - * @param string $name |
|
352 | - * @return Request |
|
353 | - */ |
|
346 | + /** |
|
347 | + * Removes a single parameter from the request. |
|
348 | + * If the parameter has been registered, also |
|
349 | + * removes the registration info. |
|
350 | + * |
|
351 | + * @param string $name |
|
352 | + * @return Request |
|
353 | + */ |
|
354 | 354 | public function removeParam(string $name) : Request |
355 | 355 | { |
356 | 356 | if(isset($_REQUEST[$name])) { |
@@ -364,12 +364,12 @@ discard block |
||
364 | 364 | return $this; |
365 | 365 | } |
366 | 366 | |
367 | - /** |
|
368 | - * Removes several parameters from the request. |
|
369 | - * |
|
370 | - * @param string[] $names |
|
371 | - * @return Request |
|
372 | - */ |
|
367 | + /** |
|
368 | + * Removes several parameters from the request. |
|
369 | + * |
|
370 | + * @param string[] $names |
|
371 | + * @return Request |
|
372 | + */ |
|
373 | 373 | public function removeParams(array $names) : Request |
374 | 374 | { |
375 | 375 | foreach($names as $name) { |
@@ -434,18 +434,18 @@ discard block |
||
434 | 434 | return $val; |
435 | 435 | } |
436 | 436 | |
437 | - /** |
|
438 | - * Treats the request parameter as a JSON string, and |
|
439 | - * if it exists and contains valid JSON, returns the |
|
440 | - * decoded JSON value as an array (default). |
|
441 | - * |
|
442 | - * @param string $name |
|
443 | - * @param bool $assoc |
|
444 | - * @return array|object |
|
445 | - * |
|
446 | - * @see Request::getJSONAssoc() |
|
447 | - * @see Request::getJSONObject() |
|
448 | - */ |
|
437 | + /** |
|
438 | + * Treats the request parameter as a JSON string, and |
|
439 | + * if it exists and contains valid JSON, returns the |
|
440 | + * decoded JSON value as an array (default). |
|
441 | + * |
|
442 | + * @param string $name |
|
443 | + * @param bool $assoc |
|
444 | + * @return array|object |
|
445 | + * |
|
446 | + * @see Request::getJSONAssoc() |
|
447 | + * @see Request::getJSONObject() |
|
448 | + */ |
|
449 | 449 | public function getJSON(string $name, bool $assoc=true) |
450 | 450 | { |
451 | 451 | $value = $this->getParam($name); |
@@ -470,13 +470,13 @@ discard block |
||
470 | 470 | return new \stdClass(); |
471 | 471 | } |
472 | 472 | |
473 | - /** |
|
474 | - * Like {@link Request::getJSON()}, but omitting the second |
|
475 | - * parameter. Use this for more readable code. |
|
476 | - * |
|
477 | - * @param string $name |
|
478 | - * @return array |
|
479 | - */ |
|
473 | + /** |
|
474 | + * Like {@link Request::getJSON()}, but omitting the second |
|
475 | + * parameter. Use this for more readable code. |
|
476 | + * |
|
477 | + * @param string $name |
|
478 | + * @return array |
|
479 | + */ |
|
480 | 480 | public function getJSONAssoc(string $name) : array |
481 | 481 | { |
482 | 482 | $result = $this->getJSON($name); |
@@ -487,13 +487,13 @@ discard block |
||
487 | 487 | return array(); |
488 | 488 | } |
489 | 489 | |
490 | - /** |
|
491 | - * Like {@link Request::getJSON()}, but omitting the second |
|
492 | - * parameter. Use this for more readable code. |
|
493 | - * |
|
494 | - * @param string $name |
|
495 | - * @return object |
|
496 | - */ |
|
490 | + /** |
|
491 | + * Like {@link Request::getJSON()}, but omitting the second |
|
492 | + * parameter. Use this for more readable code. |
|
493 | + * |
|
494 | + * @param string $name |
|
495 | + * @return object |
|
496 | + */ |
|
497 | 497 | public function getJSONObject(string $name) : object |
498 | 498 | { |
499 | 499 | $result = $this->getJSON($name, false); |
@@ -504,12 +504,12 @@ discard block |
||
504 | 504 | return new \stdClass(); |
505 | 505 | } |
506 | 506 | |
507 | - /** |
|
508 | - * Sends a JSON response with the correct headers. |
|
509 | - * |
|
510 | - * @param array|string $data |
|
511 | - * @param bool $exit Whether to exit the script afterwards. |
|
512 | - */ |
|
507 | + /** |
|
508 | + * Sends a JSON response with the correct headers. |
|
509 | + * |
|
510 | + * @param array|string $data |
|
511 | + * @param bool $exit Whether to exit the script afterwards. |
|
512 | + */ |
|
513 | 513 | public static function sendJSON($data, bool $exit=true) |
514 | 514 | { |
515 | 515 | $payload = $data; |
@@ -529,12 +529,12 @@ discard block |
||
529 | 529 | } |
530 | 530 | } |
531 | 531 | |
532 | - /** |
|
533 | - * Sends HTML to the browser with the correct headers. |
|
534 | - * |
|
535 | - * @param string $html |
|
536 | - * @param bool $exit Whether to exit the script afterwards. |
|
537 | - */ |
|
532 | + /** |
|
533 | + * Sends HTML to the browser with the correct headers. |
|
534 | + * |
|
535 | + * @param string $html |
|
536 | + * @param bool $exit Whether to exit the script afterwards. |
|
537 | + */ |
|
538 | 538 | public static function sendHTML(string $html, bool $exit=true) |
539 | 539 | { |
540 | 540 | header('Cache-Control: no-cache, must-revalidate'); |
@@ -549,16 +549,16 @@ discard block |
||
549 | 549 | } |
550 | 550 | } |
551 | 551 | |
552 | - /** |
|
553 | - * Creates a new instance of the URL comparer, which can check |
|
554 | - * whether the specified URLs match, regardless of the order in |
|
555 | - * which the query parameters are, if any. |
|
556 | - * |
|
557 | - * @param string $sourceURL |
|
558 | - * @param string $targetURL |
|
559 | - * @param array $limitParams Whether to limit the comparison to these specific parameter names (if present) |
|
560 | - * @return Request_URLComparer |
|
561 | - */ |
|
552 | + /** |
|
553 | + * Creates a new instance of the URL comparer, which can check |
|
554 | + * whether the specified URLs match, regardless of the order in |
|
555 | + * which the query parameters are, if any. |
|
556 | + * |
|
557 | + * @param string $sourceURL |
|
558 | + * @param string $targetURL |
|
559 | + * @param array $limitParams Whether to limit the comparison to these specific parameter names (if present) |
|
560 | + * @return Request_URLComparer |
|
561 | + */ |
|
562 | 562 | public function createURLComparer(string $sourceURL, string $targetURL, array $limitParams=array()) : Request_URLComparer |
563 | 563 | { |
564 | 564 | $comparer = new Request_URLComparer($this, $sourceURL, $targetURL); |
@@ -567,10 +567,10 @@ discard block |
||
567 | 567 | return $comparer; |
568 | 568 | } |
569 | 569 | |
570 | - /** |
|
571 | - * Retrieves the full URL that was used to access the current page. |
|
572 | - * @return string |
|
573 | - */ |
|
570 | + /** |
|
571 | + * Retrieves the full URL that was used to access the current page. |
|
572 | + * @return string |
|
573 | + */ |
|
574 | 574 | public function getCurrentURL() : string |
575 | 575 | { |
576 | 576 | return $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; |
@@ -90,11 +90,11 @@ discard block |
||
90 | 90 | public function getParam($name, $default = null) |
91 | 91 | { |
92 | 92 | $value = $default; |
93 | - if(isset($_REQUEST[$name])) { |
|
93 | + if (isset($_REQUEST[$name])) { |
|
94 | 94 | $value = $_REQUEST[$name]; |
95 | 95 | } |
96 | 96 | |
97 | - if(isset($this->knownParams[$name])) { |
|
97 | + if (isset($this->knownParams[$name])) { |
|
98 | 98 | $value = $this->knownParams[$name]->validate($value); |
99 | 99 | } |
100 | 100 | |
@@ -143,9 +143,9 @@ discard block |
||
143 | 143 | |
144 | 144 | $exclude = array_merge($exclude, $this->getExcludeParams()); |
145 | 145 | |
146 | - foreach($exclude as $name) |
|
146 | + foreach ($exclude as $name) |
|
147 | 147 | { |
148 | - if(isset($vars[$name])) |
|
148 | + if (isset($vars[$name])) |
|
149 | 149 | { |
150 | 150 | unset($vars[$name]); |
151 | 151 | } |
@@ -156,9 +156,9 @@ discard block |
||
156 | 156 | // remove the HTML_QuickForm2 form variable if present, to |
157 | 157 | // avoid redirect loops when using the refresh URL in |
158 | 158 | // a page in which a form has been submitted. |
159 | - foreach($names as $name) |
|
159 | + foreach ($names as $name) |
|
160 | 160 | { |
161 | - if(strstr($name, '_qf__')) |
|
161 | + if (strstr($name, '_qf__')) |
|
162 | 162 | { |
163 | 163 | unset($vars[$name]); |
164 | 164 | break; |
@@ -186,13 +186,13 @@ discard block |
||
186 | 186 | * @param string $dispatcher Relative path to script to use for the URL. Append trailing slash if needed. |
187 | 187 | * @return string |
188 | 188 | */ |
189 | - public function buildURL($params = array(), string $dispatcher='') |
|
189 | + public function buildURL($params = array(), string $dispatcher = '') |
|
190 | 190 | { |
191 | - $url = rtrim($this->getBaseURL(), '/') . '/' . $dispatcher; |
|
191 | + $url = rtrim($this->getBaseURL(), '/').'/'.$dispatcher; |
|
192 | 192 | |
193 | 193 | // append any leftover parameters to the end of the URL |
194 | 194 | if (!empty($params)) { |
195 | - $url .= '?' . http_build_query($params, null, '&'); |
|
195 | + $url .= '?'.http_build_query($params, null, '&'); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | return $url; |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | */ |
224 | 224 | public function registerParam($name) |
225 | 225 | { |
226 | - if(!isset($this->knownParams[$name])) { |
|
226 | + if (!isset($this->knownParams[$name])) { |
|
227 | 227 | $param = new Request_Param($this, $name); |
228 | 228 | $this->knownParams[$name] = $param; |
229 | 229 | } |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | */ |
241 | 241 | public function getRegisteredParam(string $name) : Request_Param |
242 | 242 | { |
243 | - if(isset($this->knownParams[$name])) { |
|
243 | + if (isset($this->knownParams[$name])) { |
|
244 | 244 | return $this->knownParams[$name]; |
245 | 245 | } |
246 | 246 | |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | { |
301 | 301 | static $accept; |
302 | 302 | |
303 | - if(!isset($accept)) { |
|
303 | + if (!isset($accept)) { |
|
304 | 304 | $accept = new Request_AcceptHeaders(); |
305 | 305 | } |
306 | 306 | |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | { |
320 | 320 | $_REQUEST[$name] = $value; |
321 | 321 | |
322 | - if(isset($this->knownParams[$name])) { |
|
322 | + if (isset($this->knownParams[$name])) { |
|
323 | 323 | unset($this->knownParams[$name]); |
324 | 324 | } |
325 | 325 | |
@@ -353,11 +353,11 @@ discard block |
||
353 | 353 | */ |
354 | 354 | public function removeParam(string $name) : Request |
355 | 355 | { |
356 | - if(isset($_REQUEST[$name])) { |
|
356 | + if (isset($_REQUEST[$name])) { |
|
357 | 357 | unset($_REQUEST[$name]); |
358 | 358 | } |
359 | 359 | |
360 | - if(isset($this->knownParams[$name])) { |
|
360 | + if (isset($this->knownParams[$name])) { |
|
361 | 361 | unset($this->knownParams[$name]); |
362 | 362 | } |
363 | 363 | |
@@ -372,7 +372,7 @@ discard block |
||
372 | 372 | */ |
373 | 373 | public function removeParams(array $names) : Request |
374 | 374 | { |
375 | - foreach($names as $name) { |
|
375 | + foreach ($names as $name) { |
|
376 | 376 | $this->removeParam($name); |
377 | 377 | } |
378 | 378 | |
@@ -388,10 +388,10 @@ discard block |
||
388 | 388 | * @param string $name |
389 | 389 | * @return bool |
390 | 390 | */ |
391 | - public function getBool($name, $default=false) |
|
391 | + public function getBool($name, $default = false) |
|
392 | 392 | { |
393 | 393 | $value = $this->getParam($name, $default); |
394 | - if(ConvertHelper::isBoolean($value)) { |
|
394 | + if (ConvertHelper::isBoolean($value)) { |
|
395 | 395 | return ConvertHelper::string2bool($value); |
396 | 396 | } |
397 | 397 | |
@@ -400,9 +400,9 @@ discard block |
||
400 | 400 | |
401 | 401 | public function validate() |
402 | 402 | { |
403 | - foreach($this->knownParams as $param) { |
|
403 | + foreach ($this->knownParams as $param) { |
|
404 | 404 | $name = $param->getName(); |
405 | - if($param->isRequired() && !$this->hasParam($name)) { |
|
405 | + if ($param->isRequired() && !$this->hasParam($name)) { |
|
406 | 406 | throw new Request_Exception( |
407 | 407 | 'Missing request parameter '.$name, |
408 | 408 | sprintf( |
@@ -424,10 +424,10 @@ discard block |
||
424 | 424 | * @param mixed $default |
425 | 425 | * @return string |
426 | 426 | */ |
427 | - public function getFilteredParam($name, $default=null) |
|
427 | + public function getFilteredParam($name, $default = null) |
|
428 | 428 | { |
429 | 429 | $val = $this->getParam($name, $default); |
430 | - if(is_string($val)) { |
|
430 | + if (is_string($val)) { |
|
431 | 431 | $val = htmlspecialchars(trim(strip_tags($val)), ENT_QUOTES, 'UTF-8'); |
432 | 432 | } |
433 | 433 | |
@@ -446,24 +446,24 @@ discard block |
||
446 | 446 | * @see Request::getJSONAssoc() |
447 | 447 | * @see Request::getJSONObject() |
448 | 448 | */ |
449 | - public function getJSON(string $name, bool $assoc=true) |
|
449 | + public function getJSON(string $name, bool $assoc = true) |
|
450 | 450 | { |
451 | 451 | $value = $this->getParam($name); |
452 | 452 | |
453 | - if(!empty($value) && is_string($value)) |
|
453 | + if (!empty($value) && is_string($value)) |
|
454 | 454 | { |
455 | 455 | $data = json_decode($value, $assoc); |
456 | 456 | |
457 | - if($assoc && is_array($data)) { |
|
457 | + if ($assoc && is_array($data)) { |
|
458 | 458 | return $data; |
459 | 459 | } |
460 | 460 | |
461 | - if(is_object($data)) { |
|
461 | + if (is_object($data)) { |
|
462 | 462 | return $data; |
463 | 463 | } |
464 | 464 | } |
465 | 465 | |
466 | - if($assoc) { |
|
466 | + if ($assoc) { |
|
467 | 467 | return array(); |
468 | 468 | } |
469 | 469 | |
@@ -480,7 +480,7 @@ discard block |
||
480 | 480 | public function getJSONAssoc(string $name) : array |
481 | 481 | { |
482 | 482 | $result = $this->getJSON($name); |
483 | - if(is_array($result)) { |
|
483 | + if (is_array($result)) { |
|
484 | 484 | return $result; |
485 | 485 | } |
486 | 486 | |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | public function getJSONObject(string $name) : object |
498 | 498 | { |
499 | 499 | $result = $this->getJSON($name, false); |
500 | - if(is_object($result)) { |
|
500 | + if (is_object($result)) { |
|
501 | 501 | return $result; |
502 | 502 | } |
503 | 503 | |
@@ -510,10 +510,10 @@ discard block |
||
510 | 510 | * @param array|string $data |
511 | 511 | * @param bool $exit Whether to exit the script afterwards. |
512 | 512 | */ |
513 | - public static function sendJSON($data, bool $exit=true) |
|
513 | + public static function sendJSON($data, bool $exit = true) |
|
514 | 514 | { |
515 | 515 | $payload = $data; |
516 | - if(!is_string($payload)) { |
|
516 | + if (!is_string($payload)) { |
|
517 | 517 | $payload = json_encode($payload); |
518 | 518 | } |
519 | 519 | |
@@ -523,7 +523,7 @@ discard block |
||
523 | 523 | |
524 | 524 | echo $payload; |
525 | 525 | |
526 | - if($exit) |
|
526 | + if ($exit) |
|
527 | 527 | { |
528 | 528 | exit; |
529 | 529 | } |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | * @param string $html |
536 | 536 | * @param bool $exit Whether to exit the script afterwards. |
537 | 537 | */ |
538 | - public static function sendHTML(string $html, bool $exit=true) |
|
538 | + public static function sendHTML(string $html, bool $exit = true) |
|
539 | 539 | { |
540 | 540 | header('Cache-Control: no-cache, must-revalidate'); |
541 | 541 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
@@ -543,7 +543,7 @@ discard block |
||
543 | 543 | |
544 | 544 | echo $html; |
545 | 545 | |
546 | - if($exit) |
|
546 | + if ($exit) |
|
547 | 547 | { |
548 | 548 | exit; |
549 | 549 | } |
@@ -559,7 +559,7 @@ discard block |
||
559 | 559 | * @param array $limitParams Whether to limit the comparison to these specific parameter names (if present) |
560 | 560 | * @return Request_URLComparer |
561 | 561 | */ |
562 | - public function createURLComparer(string $sourceURL, string $targetURL, array $limitParams=array()) : Request_URLComparer |
|
562 | + public function createURLComparer(string $sourceURL, string $targetURL, array $limitParams = array()) : Request_URLComparer |
|
563 | 563 | { |
564 | 564 | $comparer = new Request_URLComparer($this, $sourceURL, $targetURL); |
565 | 565 | $comparer->addLimitParams($limitParams); |
@@ -28,20 +28,20 @@ discard block |
||
28 | 28 | $this->parse(); |
29 | 29 | } |
30 | 30 | |
31 | - /** |
|
32 | - * Retrieves an indexed array with accept mime types |
|
33 | - * that the client sent, in the order of preference |
|
34 | - * the client specified. |
|
35 | - * |
|
36 | - * Example: |
|
37 | - * |
|
38 | - * array( |
|
39 | - * 'text/html', |
|
40 | - * 'application/xhtml+xml', |
|
41 | - * 'image/webp' |
|
42 | - * ... |
|
43 | - * ) |
|
44 | - */ |
|
31 | + /** |
|
32 | + * Retrieves an indexed array with accept mime types |
|
33 | + * that the client sent, in the order of preference |
|
34 | + * the client specified. |
|
35 | + * |
|
36 | + * Example: |
|
37 | + * |
|
38 | + * array( |
|
39 | + * 'text/html', |
|
40 | + * 'application/xhtml+xml', |
|
41 | + * 'image/webp' |
|
42 | + * ... |
|
43 | + * ) |
|
44 | + */ |
|
45 | 45 | public function getMimeStrings() : array |
46 | 46 | { |
47 | 47 | $result = array(); |
@@ -54,9 +54,9 @@ discard block |
||
54 | 54 | return $result; |
55 | 55 | } |
56 | 56 | |
57 | - /** |
|
58 | - * Checks that an accept header string exists, and tries to parse it. |
|
59 | - */ |
|
57 | + /** |
|
58 | + * Checks that an accept header string exists, and tries to parse it. |
|
59 | + */ |
|
60 | 60 | protected function parse() : void |
61 | 61 | { |
62 | 62 | // we may be in a CLI environment where the headers |
@@ -68,11 +68,11 @@ discard block |
||
68 | 68 | $this->headers = $this->parseHeader($_SERVER['HTTP_ACCEPT']); |
69 | 69 | } |
70 | 70 | |
71 | - /** |
|
72 | - * Splits the accept header string and parses the mime types. |
|
73 | - * |
|
74 | - * @param string $acceptHeader |
|
75 | - */ |
|
71 | + /** |
|
72 | + * Splits the accept header string and parses the mime types. |
|
73 | + * |
|
74 | + * @param string $acceptHeader |
|
75 | + */ |
|
76 | 76 | protected function parseHeader(string $acceptHeader) : array |
77 | 77 | { |
78 | 78 | $tokens = preg_split('/\s*,\s*/', $acceptHeader); |
@@ -89,13 +89,13 @@ discard block |
||
89 | 89 | return $accept; |
90 | 90 | } |
91 | 91 | |
92 | - /** |
|
93 | - * Parses a single mime type entry. |
|
94 | - * |
|
95 | - * @param int $i The position in the accept string |
|
96 | - * @param string $mime The mime type |
|
97 | - * @return array |
|
98 | - */ |
|
92 | + /** |
|
93 | + * Parses a single mime type entry. |
|
94 | + * |
|
95 | + * @param int $i The position in the accept string |
|
96 | + * @param string $mime The mime type |
|
97 | + * @return array |
|
98 | + */ |
|
99 | 99 | protected function parseEntry(int $i, string $mime) : array |
100 | 100 | { |
101 | 101 | $entry = array( |
@@ -125,14 +125,14 @@ discard block |
||
125 | 125 | return $entry; |
126 | 126 | } |
127 | 127 | |
128 | - /** |
|
129 | - * Sorts the mime types collection, first by quality |
|
130 | - * and then by position in the list. |
|
131 | - * |
|
132 | - * @param array $a |
|
133 | - * @param array $b |
|
134 | - * @return number |
|
135 | - */ |
|
128 | + /** |
|
129 | + * Sorts the mime types collection, first by quality |
|
130 | + * and then by position in the list. |
|
131 | + * |
|
132 | + * @param array $a |
|
133 | + * @param array $b |
|
134 | + * @return number |
|
135 | + */ |
|
136 | 136 | protected function sortMimeTypes(array $a, array $b) |
137 | 137 | { |
138 | 138 | /* first tier: highest q factor wins */ |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | { |
47 | 47 | $result = array(); |
48 | 48 | |
49 | - foreach($this->headers as $header) |
|
49 | + foreach ($this->headers as $header) |
|
50 | 50 | { |
51 | 51 | $result[] = $header['type']; |
52 | 52 | } |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | { |
62 | 62 | // we may be in a CLI environment where the headers |
63 | 63 | // are not populated. |
64 | - if(!isset($_SERVER['HTTP_ACCEPT'])) { |
|
64 | + if (!isset($_SERVER['HTTP_ACCEPT'])) { |
|
65 | 65 | return; |
66 | 66 | } |
67 | 67 | |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | |
80 | 80 | $accept = array(); |
81 | 81 | |
82 | - foreach($tokens as $i => $term) |
|
82 | + foreach ($tokens as $i => $term) |
|
83 | 83 | { |
84 | 84 | $accept[] = $this->parseEntry($i, $term); |
85 | 85 | } |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | 'type' => null |
106 | 106 | ); |
107 | 107 | |
108 | - if(strstr($mime, ';')) |
|
108 | + if (strstr($mime, ';')) |
|
109 | 109 | { |
110 | 110 | $parts = explode(';', $mime); |
111 | 111 | $mime = array_shift($parts); |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | // like an URL query string if separated by ampersands; |
115 | 115 | $entry['params'] = ConvertHelper::parseQueryString(implode('&', $parts)); |
116 | 116 | |
117 | - if(isset($entry['params']['q'])) |
|
117 | + if (isset($entry['params']['q'])) |
|
118 | 118 | { |
119 | 119 | $entry['quality'] = (double)$entry['params']['q']; |
120 | 120 | } |
@@ -141,14 +141,12 @@ |
||
141 | 141 | if ($diff > 0) |
142 | 142 | { |
143 | 143 | $diff = 1; |
144 | - } |
|
145 | - else |
|
144 | + } else |
|
146 | 145 | { |
147 | 146 | if ($diff < 0) |
148 | 147 | { |
149 | 148 | $diff = -1; |
150 | - } |
|
151 | - else |
|
149 | + } else |
|
152 | 150 | { |
153 | 151 | /* tie-breaker: first listed item wins */ |
154 | 152 | $diff = $a['pos'] - $b['pos']; |