@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | |
32 | 32 | public function addLimitParam(string $name) : Request_URLComparer |
33 | 33 | { |
34 | - if(!in_array($name, $this->limitParams)) { |
|
34 | + if (!in_array($name, $this->limitParams)) { |
|
35 | 35 | $this->limitParams[] = $name; |
36 | 36 | } |
37 | 37 | |
@@ -40,14 +40,14 @@ discard block |
||
40 | 40 | |
41 | 41 | public function addLimitParams(array $names) : Request_URLComparer |
42 | 42 | { |
43 | - foreach($names as $name) { |
|
43 | + foreach ($names as $name) { |
|
44 | 44 | $this->addLimitParam($name); |
45 | 45 | } |
46 | 46 | |
47 | 47 | return $this; |
48 | 48 | } |
49 | 49 | |
50 | - public function setIgnoreFragment(bool $ignore=true) : Request_URLComparer |
|
50 | + public function setIgnoreFragment(bool $ignore = true) : Request_URLComparer |
|
51 | 51 | { |
52 | 52 | $this->ignoreFragment = $ignore; |
53 | 53 | return $this; |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | |
56 | 56 | protected function init() |
57 | 57 | { |
58 | - if(isset($this->isMatch)) { |
|
58 | + if (isset($this->isMatch)) { |
|
59 | 59 | return; |
60 | 60 | } |
61 | 61 | |
@@ -77,25 +77,25 @@ discard block |
||
77 | 77 | 'query' |
78 | 78 | ); |
79 | 79 | |
80 | - if(!$this->ignoreFragment) { |
|
80 | + if (!$this->ignoreFragment) { |
|
81 | 81 | $keys[] = 'fragment'; |
82 | 82 | } |
83 | 83 | |
84 | - foreach($keys as $key) |
|
84 | + foreach ($keys as $key) |
|
85 | 85 | { |
86 | 86 | $sVal = ''; |
87 | 87 | $tVal = ''; |
88 | 88 | |
89 | - if(isset($sInfo[$key])) { $sVal = $sInfo[$key]; } |
|
90 | - if(isset($tInfo[$key])) { $tVal = $tInfo[$key]; } |
|
89 | + if (isset($sInfo[$key])) { $sVal = $sInfo[$key]; } |
|
90 | + if (isset($tInfo[$key])) { $tVal = $tInfo[$key]; } |
|
91 | 91 | |
92 | 92 | $filter = 'filter_'.$key; |
93 | - if(method_exists($this, $filter)) { |
|
93 | + if (method_exists($this, $filter)) { |
|
94 | 94 | $sVal = $this->$filter($sVal); |
95 | 95 | $tVal = $this->$filter($tVal); |
96 | 96 | } |
97 | 97 | |
98 | - if($sVal !== $tVal) { |
|
98 | + if ($sVal !== $tVal) { |
|
99 | 99 | return false; |
100 | 100 | } |
101 | 101 | } |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | protected function filter_path(string $path) : string |
107 | 107 | { |
108 | 108 | // fix double slashes in URLs |
109 | - while(stristr($path, '//')) { |
|
109 | + while (stristr($path, '//')) { |
|
110 | 110 | $path = str_replace('//', '/', $path); |
111 | 111 | } |
112 | 112 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | |
116 | 116 | protected function filter_query(string $query) : string |
117 | 117 | { |
118 | - if(empty($query)) { |
|
118 | + if (empty($query)) { |
|
119 | 119 | return ''; |
120 | 120 | } |
121 | 121 | |
@@ -123,13 +123,13 @@ discard block |
||
123 | 123 | |
124 | 124 | ksort($params); |
125 | 125 | |
126 | - if(!empty($this->limitParams)) |
|
126 | + if (!empty($this->limitParams)) |
|
127 | 127 | { |
128 | 128 | $keep = array(); |
129 | 129 | |
130 | - foreach($this->limitParams as $name) |
|
130 | + foreach ($this->limitParams as $name) |
|
131 | 131 | { |
132 | - if(isset($params[$name])) { |
|
132 | + if (isset($params[$name])) { |
|
133 | 133 | $keep[$name] = $params[$name]; |
134 | 134 | } |
135 | 135 | } |
@@ -111,18 +111,18 @@ discard block |
||
111 | 111 | } |
112 | 112 | } |
113 | 113 | |
114 | - /** |
|
115 | - * Adds a callback as a validation method. The callback gets the |
|
116 | - * value to validate as first parameter, and any additional |
|
117 | - * parameters passed here get appended to that. |
|
118 | - * |
|
119 | - * The callback must return boolean true or false depending on |
|
120 | - * whether the value is valid. |
|
121 | - * |
|
122 | - * @param mixed $callback |
|
123 | - * @param array $args |
|
124 | - * @return Request_Param |
|
125 | - */ |
|
114 | + /** |
|
115 | + * Adds a callback as a validation method. The callback gets the |
|
116 | + * value to validate as first parameter, and any additional |
|
117 | + * parameters passed here get appended to that. |
|
118 | + * |
|
119 | + * The callback must return boolean true or false depending on |
|
120 | + * whether the value is valid. |
|
121 | + * |
|
122 | + * @param mixed $callback |
|
123 | + * @param array $args |
|
124 | + * @return Request_Param |
|
125 | + */ |
|
126 | 126 | public function setCallback($callback, $args=array()) |
127 | 127 | { |
128 | 128 | if(!is_callable($callback)) { |
@@ -264,13 +264,13 @@ discard block |
||
264 | 264 | |
265 | 265 | protected $valueType = self::VALUE_TYPE_STRING; |
266 | 266 | |
267 | - /** |
|
268 | - * Sets the variable to contain a comma-separated list of integer IDs. |
|
269 | - * Example: <code>145,248,4556</code>. A single ID is also allowed, e.g. |
|
270 | - * <code>145</code>. |
|
271 | - * |
|
272 | - * @return Request_Param |
|
273 | - */ |
|
267 | + /** |
|
268 | + * Sets the variable to contain a comma-separated list of integer IDs. |
|
269 | + * Example: <code>145,248,4556</code>. A single ID is also allowed, e.g. |
|
270 | + * <code>145</code>. |
|
271 | + * |
|
272 | + * @return Request_Param |
|
273 | + */ |
|
274 | 274 | public function setIDList() |
275 | 275 | { |
276 | 276 | $this->valueType = self::VALUE_TYPE_ID_LIST; |
@@ -279,13 +279,13 @@ discard block |
||
279 | 279 | return $this; |
280 | 280 | } |
281 | 281 | |
282 | - /** |
|
283 | - * Sets the variable to be an alias, as defined by the |
|
284 | - * {@link RegexHelper::REGEX_ALIAS} regular expression. |
|
285 | - * |
|
286 | - * @return Request_Param |
|
287 | - * @see RegexHelper::REGEX_ALIAS |
|
288 | - */ |
|
282 | + /** |
|
283 | + * Sets the variable to be an alias, as defined by the |
|
284 | + * {@link RegexHelper::REGEX_ALIAS} regular expression. |
|
285 | + * |
|
286 | + * @return Request_Param |
|
287 | + * @see RegexHelper::REGEX_ALIAS |
|
288 | + */ |
|
289 | 289 | public function setAlias() |
290 | 290 | { |
291 | 291 | return $this->setRegex(RegexHelper::REGEX_ALIAS); |
@@ -326,12 +326,12 @@ discard block |
||
326 | 326 | return $this->setValidation(self::VALIDATION_TYPE_ALPHA); |
327 | 327 | } |
328 | 328 | |
329 | - /** |
|
330 | - * Sets the parameter value as a string containing lowercase |
|
331 | - * and/or uppercase letters, as well as numbers. |
|
332 | - * |
|
333 | - * @return Request_Param |
|
334 | - */ |
|
329 | + /** |
|
330 | + * Sets the parameter value as a string containing lowercase |
|
331 | + * and/or uppercase letters, as well as numbers. |
|
332 | + * |
|
333 | + * @return Request_Param |
|
334 | + */ |
|
335 | 335 | public function setAlnum() |
336 | 336 | { |
337 | 337 | return $this->setValidation(self::VALIDATION_TYPE_ALNUM); |
@@ -359,17 +359,17 @@ discard block |
||
359 | 359 | return $this->setValidation(self::VALIDATION_TYPE_ENUM, $args); |
360 | 360 | } |
361 | 361 | |
362 | - /** |
|
363 | - * Only available for array values: the parameter must be |
|
364 | - * an array value, and the array may only contain values |
|
365 | - * specified in the values array. |
|
366 | - * |
|
367 | - * Submitted values that are not in the allowed list of |
|
368 | - * values are stripped from the value. |
|
369 | - * |
|
370 | - * @param array $values List of allowed values |
|
371 | - * @return \AppUtils\Request_Param |
|
372 | - */ |
|
362 | + /** |
|
363 | + * Only available for array values: the parameter must be |
|
364 | + * an array value, and the array may only contain values |
|
365 | + * specified in the values array. |
|
366 | + * |
|
367 | + * Submitted values that are not in the allowed list of |
|
368 | + * values are stripped from the value. |
|
369 | + * |
|
370 | + * @param array $values List of allowed values |
|
371 | + * @return \AppUtils\Request_Param |
|
372 | + */ |
|
373 | 373 | public function setValuesList(array $values) |
374 | 374 | { |
375 | 375 | $this->setArray(); |
@@ -382,39 +382,39 @@ discard block |
||
382 | 382 | return $this->setValidation(self::VALIDATION_TYPE_ARRAY); |
383 | 383 | } |
384 | 384 | |
385 | - /** |
|
386 | - * Specifies that a JSON-encoded string is expected. |
|
387 | - * |
|
388 | - * NOTE: Numbers or quoted strings are technically valid |
|
389 | - * JSON, but are not accepted, because it is assumed |
|
390 | - * at least an array or object are expected. |
|
391 | - * |
|
392 | - * @return \AppUtils\Request_Param |
|
393 | - */ |
|
385 | + /** |
|
386 | + * Specifies that a JSON-encoded string is expected. |
|
387 | + * |
|
388 | + * NOTE: Numbers or quoted strings are technically valid |
|
389 | + * JSON, but are not accepted, because it is assumed |
|
390 | + * at least an array or object are expected. |
|
391 | + * |
|
392 | + * @return \AppUtils\Request_Param |
|
393 | + */ |
|
394 | 394 | public function setJSON() : Request_Param |
395 | 395 | { |
396 | 396 | return $this->setValidation(self::VALIDATION_TYPE_JSON, array('arrays' => true)); |
397 | 397 | } |
398 | 398 | |
399 | - /** |
|
400 | - * Like {@link Request_Param::setJSON()}, but accepts |
|
401 | - * only JSON objects. Arrays will not be accepted. |
|
402 | - * |
|
403 | - * @return \AppUtils\Request_Param |
|
404 | - */ |
|
399 | + /** |
|
400 | + * Like {@link Request_Param::setJSON()}, but accepts |
|
401 | + * only JSON objects. Arrays will not be accepted. |
|
402 | + * |
|
403 | + * @return \AppUtils\Request_Param |
|
404 | + */ |
|
405 | 405 | public function setJSONObject() : Request_Param |
406 | 406 | { |
407 | 407 | return $this->setValidation(self::VALIDATION_TYPE_JSON, array('arrays' => false)); |
408 | 408 | } |
409 | 409 | |
410 | - /** |
|
411 | - * The parameter is a string boolean representation. This means |
|
412 | - * it can be any of the following: "yes", "true", "no", "false". |
|
413 | - * The value is automatically converted to a boolean when retrieving |
|
414 | - * the parameter. |
|
415 | - * |
|
416 | - * @return Request_Param |
|
417 | - */ |
|
410 | + /** |
|
411 | + * The parameter is a string boolean representation. This means |
|
412 | + * it can be any of the following: "yes", "true", "no", "false". |
|
413 | + * The value is automatically converted to a boolean when retrieving |
|
414 | + * the parameter. |
|
415 | + * |
|
416 | + * @return Request_Param |
|
417 | + */ |
|
418 | 418 | public function setBoolean() : Request_Param |
419 | 419 | { |
420 | 420 | $this->addCallbackFilter(array($this, 'applyFilter_boolean')); |
@@ -478,15 +478,15 @@ discard block |
||
478 | 478 | return $keep; |
479 | 479 | } |
480 | 480 | |
481 | - /** |
|
482 | - * Validates the request parameter as an MD5 string, |
|
483 | - * so that only values resembling md5 values are accepted. |
|
484 | - * |
|
485 | - * NOTE: This can only guarantee the format, not whether |
|
486 | - * it is an actual valid hash of something. |
|
487 | - * |
|
488 | - * @return \AppUtils\Request_Param |
|
489 | - */ |
|
481 | + /** |
|
482 | + * Validates the request parameter as an MD5 string, |
|
483 | + * so that only values resembling md5 values are accepted. |
|
484 | + * |
|
485 | + * NOTE: This can only guarantee the format, not whether |
|
486 | + * it is an actual valid hash of something. |
|
487 | + * |
|
488 | + * @return \AppUtils\Request_Param |
|
489 | + */ |
|
490 | 490 | public function setMD5() : Request_Param |
491 | 491 | { |
492 | 492 | return $this->setRegex(RegexHelper::REGEX_MD5); |
@@ -528,14 +528,14 @@ discard block |
||
528 | 528 | return $this; |
529 | 529 | } |
530 | 530 | |
531 | - /** |
|
532 | - * Retrieves the value of the request parameter, |
|
533 | - * applying all filters (if any) and validation |
|
534 | - * (if any). |
|
535 | - * |
|
536 | - * @param mixed $default |
|
537 | - * @return mixed |
|
538 | - */ |
|
531 | + /** |
|
532 | + * Retrieves the value of the request parameter, |
|
533 | + * applying all filters (if any) and validation |
|
534 | + * (if any). |
|
535 | + * |
|
536 | + * @param mixed $default |
|
537 | + * @return mixed |
|
538 | + */ |
|
539 | 539 | public function get($default=null) |
540 | 540 | { |
541 | 541 | $value = $this->validate($this->request->getParam($this->paramName)); |
@@ -566,11 +566,11 @@ discard block |
||
566 | 566 | return $int; |
567 | 567 | } |
568 | 568 | |
569 | - /** |
|
570 | - * Validates the syntax of an URL, but not its actual validity. |
|
571 | - * @param string $value |
|
572 | - * @return string |
|
573 | - */ |
|
569 | + /** |
|
570 | + * Validates the syntax of an URL, but not its actual validity. |
|
571 | + * @param string $value |
|
572 | + * @return string |
|
573 | + */ |
|
574 | 574 | protected function validate_url($value) : string |
575 | 575 | { |
576 | 576 | if(!is_string($value)) { |
@@ -689,10 +689,10 @@ discard block |
||
689 | 689 | return null; |
690 | 690 | } |
691 | 691 | |
692 | - /** |
|
693 | - * Makes sure that the value is a JSON-encoded string. |
|
694 | - * @param string $value |
|
695 | - */ |
|
692 | + /** |
|
693 | + * Makes sure that the value is a JSON-encoded string. |
|
694 | + * @param string $value |
|
695 | + */ |
|
696 | 696 | protected function validate_json($value) |
697 | 697 | { |
698 | 698 | if(!is_string($value)) { |
@@ -709,7 +709,7 @@ discard block |
||
709 | 709 | if($this->validationParams['arrays'] === false) |
710 | 710 | { |
711 | 711 | if(is_object(json_decode($value))) { |
712 | - return $value; |
|
712 | + return $value; |
|
713 | 713 | } |
714 | 714 | } |
715 | 715 | else |
@@ -790,12 +790,12 @@ discard block |
||
790 | 790 | return $this; |
791 | 791 | } |
792 | 792 | |
793 | - /** |
|
794 | - * Adds a filter that trims whitespace from the request |
|
795 | - * parameter using the PHP <code>trim</code> function. |
|
796 | - * |
|
797 | - * @return \AppUtils\Request_Param |
|
798 | - */ |
|
793 | + /** |
|
794 | + * Adds a filter that trims whitespace from the request |
|
795 | + * parameter using the PHP <code>trim</code> function. |
|
796 | + * |
|
797 | + * @return \AppUtils\Request_Param |
|
798 | + */ |
|
799 | 799 | public function addFilterTrim() : Request_Param |
800 | 800 | { |
801 | 801 | // to guarantee we only work with strings |
@@ -804,13 +804,13 @@ discard block |
||
804 | 804 | return $this->addCallbackFilter('trim'); |
805 | 805 | } |
806 | 806 | |
807 | - /** |
|
808 | - * Converts the value to a string, even if it is not |
|
809 | - * a string value. Complex types like arrays and objects |
|
810 | - * are converted to an empty string. |
|
811 | - * |
|
812 | - * @return \AppUtils\Request_Param |
|
813 | - */ |
|
807 | + /** |
|
808 | + * Converts the value to a string, even if it is not |
|
809 | + * a string value. Complex types like arrays and objects |
|
810 | + * are converted to an empty string. |
|
811 | + * |
|
812 | + * @return \AppUtils\Request_Param |
|
813 | + */ |
|
814 | 814 | public function addStringFilter() : Request_Param |
815 | 815 | { |
816 | 816 | return $this->addCallbackFilter(array($this, 'applyFilter_string')); |
@@ -860,12 +860,12 @@ discard block |
||
860 | 860 | return $this->addCallbackFilter('strip_tags', array($allowedTags)); |
861 | 861 | } |
862 | 862 | |
863 | - /** |
|
864 | - * Adds a filter that strips all whitespace from the |
|
865 | - * request parameter, from spaces to tabs and newlines. |
|
866 | - * |
|
867 | - * @return \AppUtils\Request_Param |
|
868 | - */ |
|
863 | + /** |
|
864 | + * Adds a filter that strips all whitespace from the |
|
865 | + * request parameter, from spaces to tabs and newlines. |
|
866 | + * |
|
867 | + * @return \AppUtils\Request_Param |
|
868 | + */ |
|
869 | 869 | public function addStripWhitespaceFilter() : Request_Param |
870 | 870 | { |
871 | 871 | // to ensure we only work with strings. |
@@ -874,14 +874,14 @@ discard block |
||
874 | 874 | return $this->addCallbackFilter(array($this, 'applyFilter_stripWhitespace')); |
875 | 875 | } |
876 | 876 | |
877 | - /** |
|
878 | - * Adds a filter that transforms comma separated values |
|
879 | - * into an array of values. |
|
880 | - * |
|
881 | - * @param bool $trimEntries Trim whitespace from each entry? |
|
882 | - * @param bool $stripEmptyEntries Remove empty entries from the array? |
|
883 | - * @return \AppUtils\Request_Param |
|
884 | - */ |
|
877 | + /** |
|
878 | + * Adds a filter that transforms comma separated values |
|
879 | + * into an array of values. |
|
880 | + * |
|
881 | + * @param bool $trimEntries Trim whitespace from each entry? |
|
882 | + * @param bool $stripEmptyEntries Remove empty entries from the array? |
|
883 | + * @return \AppUtils\Request_Param |
|
884 | + */ |
|
885 | 885 | public function addCommaSeparatedFilter(bool $trimEntries=true, bool $stripEmptyEntries=true) : Request_Param |
886 | 886 | { |
887 | 887 | $this->setArray(); |
@@ -895,12 +895,12 @@ discard block |
||
895 | 895 | ); |
896 | 896 | } |
897 | 897 | |
898 | - /** |
|
899 | - * Adds a filter that encodes all HTML special characters |
|
900 | - * using the PHP <code>htmlspecialchars</code> function. |
|
901 | - * |
|
902 | - * @return \AppUtils\Request_Param |
|
903 | - */ |
|
898 | + /** |
|
899 | + * Adds a filter that encodes all HTML special characters |
|
900 | + * using the PHP <code>htmlspecialchars</code> function. |
|
901 | + * |
|
902 | + * @return \AppUtils\Request_Param |
|
903 | + */ |
|
904 | 904 | public function addHTMLSpecialcharsFilter() : Request_Param |
905 | 905 | { |
906 | 906 | return $this->addCallbackFilter('htmlspecialchars', array(ENT_QUOTES, 'UTF-8')); |
@@ -913,14 +913,14 @@ discard block |
||
913 | 913 | |
914 | 914 | protected $required = false; |
915 | 915 | |
916 | - /** |
|
917 | - * Marks this request parameter as required. To use this feature, |
|
918 | - * you have to call the request's {@link Request::validate()} |
|
919 | - * method. |
|
920 | - * |
|
921 | - * @return Request_Param |
|
922 | - * @see Request::validate() |
|
923 | - */ |
|
916 | + /** |
|
917 | + * Marks this request parameter as required. To use this feature, |
|
918 | + * you have to call the request's {@link Request::validate()} |
|
919 | + * method. |
|
920 | + * |
|
921 | + * @return Request_Param |
|
922 | + * @see Request::validate() |
|
923 | + */ |
|
924 | 924 | public function makeRequired() : Request_Param |
925 | 925 | { |
926 | 926 | $this->required = true; |
@@ -123,9 +123,9 @@ discard block |
||
123 | 123 | * @param array $args |
124 | 124 | * @return Request_Param |
125 | 125 | */ |
126 | - public function setCallback($callback, $args=array()) |
|
126 | + public function setCallback($callback, $args = array()) |
|
127 | 127 | { |
128 | - if(!is_callable($callback)) { |
|
128 | + if (!is_callable($callback)) { |
|
129 | 129 | throw new Request_Exception( |
130 | 130 | 'Not a valid callback', |
131 | 131 | 'The specified callback is not a valid callable entity.', |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | array_unshift($args, $value); |
149 | 149 | |
150 | 150 | $result = call_user_func_array($this->validationParams['callback'], $args); |
151 | - if($result !== false) { |
|
151 | + if ($result !== false) { |
|
152 | 152 | return $value; |
153 | 153 | } |
154 | 154 | |
@@ -175,13 +175,13 @@ discard block |
||
175 | 175 | |
176 | 176 | // go through all enqueued validations in turn, each time |
177 | 177 | // replacing the value with the adjusted, validated value. |
178 | - foreach($this->validations as $validateDef) |
|
178 | + foreach ($this->validations as $validateDef) |
|
179 | 179 | { |
180 | 180 | $this->validationType = $validateDef['type']; |
181 | 181 | $this->validationParams = $validateDef['params']; |
182 | 182 | |
183 | 183 | // and now, see if we have to validate the value as well |
184 | - $method = 'validate_' . $this->validationType; |
|
184 | + $method = 'validate_'.$this->validationType; |
|
185 | 185 | if (!method_exists($this, $method)) { |
186 | 186 | throw new Request_Exception( |
187 | 187 | 'Unknown validation type.', |
@@ -195,19 +195,19 @@ discard block |
||
195 | 195 | ); |
196 | 196 | } |
197 | 197 | |
198 | - if($this->valueType === self::VALUE_TYPE_ID_LIST) |
|
198 | + if ($this->valueType === self::VALUE_TYPE_ID_LIST) |
|
199 | 199 | { |
200 | - if(!is_array($value)) { |
|
200 | + if (!is_array($value)) { |
|
201 | 201 | $value = explode(',', $value); |
202 | 202 | } |
203 | 203 | |
204 | 204 | $keep = array(); |
205 | - foreach($value as $subval) |
|
205 | + foreach ($value as $subval) |
|
206 | 206 | { |
207 | 207 | $subval = trim($subval); |
208 | 208 | $subval = $this->$method($subval); |
209 | 209 | |
210 | - if($subval !== null) { |
|
210 | + if ($subval !== null) { |
|
211 | 211 | $keep[] = intval($subval); |
212 | 212 | } |
213 | 213 | } |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | |
424 | 424 | protected function applyFilter_boolean($value) |
425 | 425 | { |
426 | - if($value == 'yes' || $value == 'true') { |
|
426 | + if ($value == 'yes' || $value == 'true') { |
|
427 | 427 | return true; |
428 | 428 | } |
429 | 429 | |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | |
438 | 438 | protected function applyFilter_string($value) |
439 | 439 | { |
440 | - if(!is_scalar($value)) { |
|
440 | + if (!is_scalar($value)) { |
|
441 | 441 | return ''; |
442 | 442 | } |
443 | 443 | |
@@ -446,29 +446,29 @@ discard block |
||
446 | 446 | |
447 | 447 | protected function applyFilter_commaSeparated($value, bool $trimEntries, bool $stripEmptyEntries) |
448 | 448 | { |
449 | - if(is_array($value)) { |
|
449 | + if (is_array($value)) { |
|
450 | 450 | return $value; |
451 | 451 | } |
452 | 452 | |
453 | - if($value === '' || $value === null || !is_string($value)) { |
|
453 | + if ($value === '' || $value === null || !is_string($value)) { |
|
454 | 454 | return array(); |
455 | 455 | } |
456 | 456 | |
457 | 457 | $result = explode(',', $value); |
458 | 458 | |
459 | - if(!$trimEntries && !$stripEmptyEntries) { |
|
459 | + if (!$trimEntries && !$stripEmptyEntries) { |
|
460 | 460 | return $result; |
461 | 461 | } |
462 | 462 | |
463 | 463 | $keep = array(); |
464 | 464 | |
465 | - foreach($result as $entry) |
|
465 | + foreach ($result as $entry) |
|
466 | 466 | { |
467 | - if($trimEntries === true) { |
|
467 | + if ($trimEntries === true) { |
|
468 | 468 | $entry = trim($entry); |
469 | 469 | } |
470 | 470 | |
471 | - if($stripEmptyEntries === true && $entry === '') { |
|
471 | + if ($stripEmptyEntries === true && $entry === '') { |
|
472 | 472 | continue; |
473 | 473 | } |
474 | 474 | |
@@ -536,10 +536,10 @@ discard block |
||
536 | 536 | * @param mixed $default |
537 | 537 | * @return mixed |
538 | 538 | */ |
539 | - public function get($default=null) |
|
539 | + public function get($default = null) |
|
540 | 540 | { |
541 | 541 | $value = $this->validate($this->request->getParam($this->paramName)); |
542 | - if($value !== null && $value !== '') { |
|
542 | + if ($value !== null && $value !== '') { |
|
543 | 543 | return $value; |
544 | 544 | } |
545 | 545 | |
@@ -573,12 +573,12 @@ discard block |
||
573 | 573 | */ |
574 | 574 | protected function validate_url($value) : string |
575 | 575 | { |
576 | - if(!is_string($value)) { |
|
576 | + if (!is_string($value)) { |
|
577 | 577 | return ''; |
578 | 578 | } |
579 | 579 | |
580 | 580 | $info = parse_url($value); |
581 | - if(isset($info['host'])) { |
|
581 | + if (isset($info['host'])) { |
|
582 | 582 | return $value; |
583 | 583 | } |
584 | 584 | |
@@ -632,13 +632,13 @@ discard block |
||
632 | 632 | |
633 | 633 | protected function validate_valueslist($value) |
634 | 634 | { |
635 | - if(!is_array($value)) { |
|
635 | + if (!is_array($value)) { |
|
636 | 636 | return array(); |
637 | 637 | } |
638 | 638 | |
639 | 639 | $keep = array(); |
640 | - foreach($value as $item) { |
|
641 | - if(in_array($item, $this->validationParams)) { |
|
640 | + foreach ($value as $item) { |
|
641 | + if (in_array($item, $this->validationParams)) { |
|
642 | 642 | $keep[] = $item; |
643 | 643 | } |
644 | 644 | } |
@@ -695,26 +695,26 @@ discard block |
||
695 | 695 | */ |
696 | 696 | protected function validate_json($value) |
697 | 697 | { |
698 | - if(!is_string($value)) { |
|
698 | + if (!is_string($value)) { |
|
699 | 699 | return ''; |
700 | 700 | } |
701 | 701 | |
702 | 702 | $value = trim($value); |
703 | 703 | |
704 | - if(empty($value)) { |
|
704 | + if (empty($value)) { |
|
705 | 705 | return ''; |
706 | 706 | } |
707 | 707 | |
708 | 708 | // strictly validate for objects? |
709 | - if($this->validationParams['arrays'] === false) |
|
709 | + if ($this->validationParams['arrays'] === false) |
|
710 | 710 | { |
711 | - if(is_object(json_decode($value))) { |
|
711 | + if (is_object(json_decode($value))) { |
|
712 | 712 | return $value; |
713 | 713 | } |
714 | 714 | } |
715 | 715 | else |
716 | 716 | { |
717 | - if(is_array(json_decode($value, true))) { |
|
717 | + if (is_array(json_decode($value, true))) { |
|
718 | 718 | return $value; |
719 | 719 | } |
720 | 720 | } |
@@ -735,7 +735,7 @@ discard block |
||
735 | 735 | { |
736 | 736 | $total = count($this->filters); |
737 | 737 | for ($i = 0; $i < $total; $i++) { |
738 | - $method = 'applyFilter_' . $this->filters[$i]['type']; |
|
738 | + $method = 'applyFilter_'.$this->filters[$i]['type']; |
|
739 | 739 | $value = $this->$method($value, $this->filters[$i]['params']); |
740 | 740 | } |
741 | 741 | |
@@ -882,7 +882,7 @@ discard block |
||
882 | 882 | * @param bool $stripEmptyEntries Remove empty entries from the array? |
883 | 883 | * @return \AppUtils\Request_Param |
884 | 884 | */ |
885 | - public function addCommaSeparatedFilter(bool $trimEntries=true, bool $stripEmptyEntries=true) : Request_Param |
|
885 | + public function addCommaSeparatedFilter(bool $trimEntries = true, bool $stripEmptyEntries = true) : Request_Param |
|
886 | 886 | { |
887 | 887 | $this->setArray(); |
888 | 888 |
@@ -711,8 +711,7 @@ |
||
711 | 711 | if(is_object(json_decode($value))) { |
712 | 712 | return $value; |
713 | 713 | } |
714 | - } |
|
715 | - else |
|
714 | + } else |
|
716 | 715 | { |
717 | 716 | if(is_array(json_decode($value, true))) { |
718 | 717 | return $value; |
@@ -42,10 +42,10 @@ discard block |
||
42 | 42 | |
43 | 43 | const REGEX_MD5 = '/^[a-f0-9]{32}$/i'; |
44 | 44 | |
45 | - /** |
|
46 | - * @var string |
|
47 | - * @see https://en.wikipedia.org/wiki/Email_address#Local-part |
|
48 | - */ |
|
45 | + /** |
|
46 | + * @var string |
|
47 | + * @see https://en.wikipedia.org/wiki/Email_address#Local-part |
|
48 | + */ |
|
49 | 49 | const REGEX_EMAIL = '/[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i'; |
50 | 50 | |
51 | 51 | const REGEX_PHONE = '/\A[+0-9][0-9 +\-()]+\z/m'; |
@@ -97,13 +97,13 @@ discard block |
||
97 | 97 | */ |
98 | 98 | const REGEX_IS_HTML = '%<{0,1}[a-z\/][\s\S]*>|<[a-z\/][\s\S]*>{0,1}%i'; |
99 | 99 | |
100 | - /** |
|
101 | - * Hexadecimal color codes. Allows the following formats: |
|
102 | - * |
|
103 | - * FFFFFF |
|
104 | - * FFF |
|
105 | - * |
|
106 | - * @var string |
|
107 | - */ |
|
100 | + /** |
|
101 | + * Hexadecimal color codes. Allows the following formats: |
|
102 | + * |
|
103 | + * FFFFFF |
|
104 | + * FFF |
|
105 | + * |
|
106 | + * @var string |
|
107 | + */ |
|
108 | 108 | const REGEX_HEX_COLOR_CODE = '/\A(?:[0-9a-fA-F]{6}|[0-9a-fA-F]{3})\z/iU'; |
109 | 109 | } |
@@ -32,24 +32,24 @@ discard block |
||
32 | 32 | self::TYPE_CALLABLE => 'cf5e20' |
33 | 33 | ); |
34 | 34 | |
35 | - /** |
|
36 | - * @var string |
|
37 | - */ |
|
35 | + /** |
|
36 | + * @var string |
|
37 | + */ |
|
38 | 38 | protected $string; |
39 | 39 | |
40 | - /** |
|
41 | - * @var array |
|
42 | - */ |
|
40 | + /** |
|
41 | + * @var array |
|
42 | + */ |
|
43 | 43 | protected $value; |
44 | 44 | |
45 | - /** |
|
46 | - * @var string |
|
47 | - */ |
|
45 | + /** |
|
46 | + * @var string |
|
47 | + */ |
|
48 | 48 | protected $type; |
49 | 49 | |
50 | - /** |
|
51 | - * @param mixed $value |
|
52 | - */ |
|
50 | + /** |
|
51 | + * @param mixed $value |
|
52 | + */ |
|
53 | 53 | public function __construct($value, $serialized=null) |
54 | 54 | { |
55 | 55 | if(is_array($serialized)) |
@@ -105,13 +105,13 @@ discard block |
||
105 | 105 | ); |
106 | 106 | } |
107 | 107 | |
108 | - /** |
|
109 | - * Whether to prepend the variable type before the value, |
|
110 | - * like the var_dump function. Example: <code>string "Some text"</code>. |
|
111 | - * |
|
112 | - * @param bool $enable |
|
113 | - * @return VariableInfo |
|
114 | - */ |
|
108 | + /** |
|
109 | + * Whether to prepend the variable type before the value, |
|
110 | + * like the var_dump function. Example: <code>string "Some text"</code>. |
|
111 | + * |
|
112 | + * @param bool $enable |
|
113 | + * @return VariableInfo |
|
114 | + */ |
|
115 | 115 | public function enableType(bool $enable=true) : VariableInfo |
116 | 116 | { |
117 | 117 | return $this->setOption('prepend-type', $enable); |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | /** |
51 | 51 | * @param mixed $value |
52 | 52 | */ |
53 | - public function __construct($value, $serialized=null) |
|
53 | + public function __construct($value, $serialized = null) |
|
54 | 54 | { |
55 | - if(is_array($serialized)) |
|
55 | + if (is_array($serialized)) |
|
56 | 56 | { |
57 | 57 | $this->parseSerialized($serialized); |
58 | 58 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | $this->value = $value; |
86 | 86 | $this->type = strtolower(gettype($value)); |
87 | 87 | |
88 | - if(is_array($value) && is_callable($value)) { |
|
88 | + if (is_array($value) && is_callable($value)) { |
|
89 | 89 | $this->type = self::TYPE_CALLABLE; |
90 | 90 | } |
91 | 91 | |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | * @param bool $enable |
113 | 113 | * @return VariableInfo |
114 | 114 | */ |
115 | - public function enableType(bool $enable=true) : VariableInfo |
|
115 | + public function enableType(bool $enable = true) : VariableInfo |
|
116 | 116 | { |
117 | 117 | return $this->setOption('prepend-type', $enable); |
118 | 118 | } |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | { |
122 | 122 | $converted = $this->string; |
123 | 123 | |
124 | - if($this->getOption('prepend-type') === true && !$this->isNull()) |
|
124 | + if ($this->getOption('prepend-type') === true && !$this->isNull()) |
|
125 | 125 | { |
126 | - if($this->isString()) |
|
126 | + if ($this->isString()) |
|
127 | 127 | { |
128 | 128 | $converted = '"'.$converted.'"'; |
129 | 129 | } |
@@ -155,16 +155,16 @@ discard block |
||
155 | 155 | |
156 | 156 | $converted = $this->$varMethod(); |
157 | 157 | |
158 | - if($format === 'HTML') |
|
158 | + if ($format === 'HTML') |
|
159 | 159 | { |
160 | 160 | $converted = '<span style="color:#'.self::$colors[$type].'" class="variable-value-'.$this->type.'">'.$converted.'</span>'; |
161 | 161 | } |
162 | 162 | |
163 | - if($this->getOption('prepend-type') === true && !$this->isNull()) |
|
163 | + if ($this->getOption('prepend-type') === true && !$this->isNull()) |
|
164 | 164 | { |
165 | 165 | $typeLabel = $type; |
166 | 166 | |
167 | - switch($format) |
|
167 | + switch ($format) |
|
168 | 168 | { |
169 | 169 | case 'HTML': |
170 | 170 | $typeLabel = '<span style="color:#1c2eb1" class="variable-type">'.$type.'</span> '; |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | { |
191 | 191 | $string = ''; |
192 | 192 | |
193 | - if(is_string($this->value[0])) { |
|
193 | + if (is_string($this->value[0])) { |
|
194 | 194 | $string .= $this->value[0].'::'; |
195 | 195 | } else { |
196 | 196 | $string .= get_class($this->value[0]).'->'; |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | str_replace(' ', '-', $this->type) |
318 | 318 | ); |
319 | 319 | |
320 | - if($this->getOption('prepend-type') === true && !$this->isNull()) |
|
320 | + if ($this->getOption('prepend-type') === true && !$this->isNull()) |
|
321 | 321 | { |
322 | 322 | $typeLabel = '<span style="color:#1c2eb1" class="variable-type">'.$this->type.'</span> '; |
323 | 323 | $converted = $typeLabel.' '.$converted; |
@@ -55,8 +55,7 @@ |
||
55 | 55 | if(is_array($serialized)) |
56 | 56 | { |
57 | 57 | $this->parseSerialized($serialized); |
58 | - } |
|
59 | - else |
|
58 | + } else |
|
60 | 59 | { |
61 | 60 | $this->parseValue($value); |
62 | 61 | } |
@@ -13,10 +13,10 @@ discard block |
||
13 | 13 | $this->details = $details; |
14 | 14 | } |
15 | 15 | |
16 | - /** |
|
17 | - * Retrieves the detailed error description, if any. |
|
18 | - * @return string |
|
19 | - */ |
|
16 | + /** |
|
17 | + * Retrieves the detailed error description, if any. |
|
18 | + * @return string |
|
19 | + */ |
|
20 | 20 | public function getDetails() : string |
21 | 21 | { |
22 | 22 | if($this->details !== null) { |
@@ -26,10 +26,10 @@ discard block |
||
26 | 26 | return ''; |
27 | 27 | } |
28 | 28 | |
29 | - /** |
|
30 | - * Displays pertinent information on the exception in |
|
31 | - * the browser, and exits the script. |
|
32 | - */ |
|
29 | + /** |
|
30 | + * Displays pertinent information on the exception in |
|
31 | + * the browser, and exits the script. |
|
32 | + */ |
|
33 | 33 | public function display() |
34 | 34 | { |
35 | 35 | if(!headers_sent()) { |
@@ -40,20 +40,20 @@ discard block |
||
40 | 40 | exit; |
41 | 41 | } |
42 | 42 | |
43 | - /** |
|
44 | - * Retrieves information on the exception that can be |
|
45 | - * easily accessed. |
|
46 | - * |
|
47 | - * @return ConvertHelper_ThrowableInfo |
|
48 | - */ |
|
43 | + /** |
|
44 | + * Retrieves information on the exception that can be |
|
45 | + * easily accessed. |
|
46 | + * |
|
47 | + * @return ConvertHelper_ThrowableInfo |
|
48 | + */ |
|
49 | 49 | public function getInfo() : ConvertHelper_ThrowableInfo |
50 | 50 | { |
51 | 51 | return ConvertHelper::throwable2info($this); |
52 | 52 | } |
53 | 53 | |
54 | - /** |
|
55 | - * Dumps a current PHP function trace, as a textonly string. |
|
56 | - */ |
|
54 | + /** |
|
55 | + * Dumps a current PHP function trace, as a textonly string. |
|
56 | + */ |
|
57 | 57 | public static function dumpTraceAsString() |
58 | 58 | { |
59 | 59 | try |
@@ -83,13 +83,13 @@ discard block |
||
83 | 83 | } |
84 | 84 | } |
85 | 85 | |
86 | - /** |
|
87 | - * Creates an exception info instance from a throwable instance. |
|
88 | - * |
|
89 | - * @param \Throwable $e |
|
90 | - * @return ConvertHelper_ThrowableInfo |
|
91 | - * @see ConvertHelper::throwable2info() |
|
92 | - */ |
|
86 | + /** |
|
87 | + * Creates an exception info instance from a throwable instance. |
|
88 | + * |
|
89 | + * @param \Throwable $e |
|
90 | + * @return ConvertHelper_ThrowableInfo |
|
91 | + * @see ConvertHelper::throwable2info() |
|
92 | + */ |
|
93 | 93 | public static function createInfo(\Throwable $e) : ConvertHelper_ThrowableInfo |
94 | 94 | { |
95 | 95 | return ConvertHelper::throwable2info($e); |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | { |
7 | 7 | protected $details; |
8 | 8 | |
9 | - public function __construct($message, $details=null, $code=null, $previous=null) |
|
9 | + public function __construct($message, $details = null, $code = null, $previous = null) |
|
10 | 10 | { |
11 | 11 | parent::__construct($message, $code, $previous); |
12 | 12 | |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | */ |
20 | 20 | public function getDetails() : string |
21 | 21 | { |
22 | - if($this->details !== null) { |
|
22 | + if ($this->details !== null) { |
|
23 | 23 | return $this->details; |
24 | 24 | } |
25 | 25 | |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function display() |
34 | 34 | { |
35 | - if(!headers_sent()) { |
|
35 | + if (!headers_sent()) { |
|
36 | 36 | header('Content-type:text/plain; charset=utf-8'); |
37 | 37 | } |
38 | 38 | |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | { |
61 | 61 | throw new BaseException(''); |
62 | 62 | } |
63 | - catch(BaseException $e) |
|
63 | + catch (BaseException $e) |
|
64 | 64 | { |
65 | 65 | echo self::createInfo($e)->toString(); |
66 | 66 | } |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | { |
76 | 76 | throw new BaseException(''); |
77 | 77 | } |
78 | - catch(BaseException $e) |
|
78 | + catch (BaseException $e) |
|
79 | 79 | { |
80 | 80 | echo '<pre style="background:#fff;font-family:monospace;font-size:14px;color:#444;padding:16px;border:solid 1px #999;border-radius:4px;">'; |
81 | 81 | echo self::createInfo($e)->toString(); |
@@ -59,8 +59,7 @@ discard block |
||
59 | 59 | try |
60 | 60 | { |
61 | 61 | throw new BaseException(''); |
62 | - } |
|
63 | - catch(BaseException $e) |
|
62 | + } catch(BaseException $e) |
|
64 | 63 | { |
65 | 64 | echo self::createInfo($e)->toString(); |
66 | 65 | } |
@@ -74,8 +73,7 @@ discard block |
||
74 | 73 | try |
75 | 74 | { |
76 | 75 | throw new BaseException(''); |
77 | - } |
|
78 | - catch(BaseException $e) |
|
76 | + } catch(BaseException $e) |
|
79 | 77 | { |
80 | 78 | echo '<pre style="background:#fff;font-family:monospace;font-size:14px;color:#444;padding:16px;border:solid 1px #999;border-radius:4px;">'; |
81 | 79 | echo self::createInfo($e)->toString(); |
@@ -52,12 +52,12 @@ discard block |
||
52 | 52 | |
53 | 53 | } |
54 | 54 | |
55 | - /** |
|
56 | - * Creates and returns a new instance of the CSV builder which |
|
57 | - * can be used to build CSV from scratch. |
|
58 | - * |
|
59 | - * @return CSVHelper_Builder |
|
60 | - */ |
|
55 | + /** |
|
56 | + * Creates and returns a new instance of the CSV builder which |
|
57 | + * can be used to build CSV from scratch. |
|
58 | + * |
|
59 | + * @return CSVHelper_Builder |
|
60 | + */ |
|
61 | 61 | public static function createBuilder() |
62 | 62 | { |
63 | 63 | return new CSVHelper_Builder(); |
@@ -71,16 +71,16 @@ discard block |
||
71 | 71 | |
72 | 72 | protected $headersPosition = self::HEADERS_NONE; |
73 | 73 | |
74 | - /** |
|
75 | - * Loads CSV data from a string. |
|
76 | - * |
|
77 | - * Note: Use the {@link hasErrors()} method to |
|
78 | - * check if the string could be parsed correctly |
|
79 | - * afterwards. |
|
80 | - * |
|
81 | - * @param string $string |
|
82 | - * @return CSVHelper |
|
83 | - */ |
|
74 | + /** |
|
75 | + * Loads CSV data from a string. |
|
76 | + * |
|
77 | + * Note: Use the {@link hasErrors()} method to |
|
78 | + * check if the string could be parsed correctly |
|
79 | + * afterwards. |
|
80 | + * |
|
81 | + * @param string $string |
|
82 | + * @return CSVHelper |
|
83 | + */ |
|
84 | 84 | public function loadString($string) |
85 | 85 | { |
86 | 86 | // remove any UTF byte order marks that may still be present in the string |
@@ -94,17 +94,17 @@ discard block |
||
94 | 94 | return $this; |
95 | 95 | } |
96 | 96 | |
97 | - /** |
|
98 | - * Loads CSV data from a file. |
|
99 | - * |
|
100 | - * Note: Use the {@link hasErrors()} method to |
|
101 | - * check if the string could be parsed correctly |
|
102 | - * afterwards. |
|
103 | - * |
|
104 | - * @param string $file |
|
105 | - * @throws CSVHelper_Exception |
|
106 | - * @return boolean |
|
107 | - */ |
|
97 | + /** |
|
98 | + * Loads CSV data from a file. |
|
99 | + * |
|
100 | + * Note: Use the {@link hasErrors()} method to |
|
101 | + * check if the string could be parsed correctly |
|
102 | + * afterwards. |
|
103 | + * |
|
104 | + * @param string $file |
|
105 | + * @throws CSVHelper_Exception |
|
106 | + * @return boolean |
|
107 | + */ |
|
108 | 108 | public function loadFile($file) |
109 | 109 | { |
110 | 110 | $csv = file_get_contents($file); |
@@ -128,28 +128,28 @@ discard block |
||
128 | 128 | |
129 | 129 | protected $rowCount = 0; |
130 | 130 | |
131 | - /** |
|
132 | - * Specifies that headers are positioned on top, horizontally. |
|
133 | - * @return CSVHelper |
|
134 | - */ |
|
131 | + /** |
|
132 | + * Specifies that headers are positioned on top, horizontally. |
|
133 | + * @return CSVHelper |
|
134 | + */ |
|
135 | 135 | public function setHeadersTop() |
136 | 136 | { |
137 | 137 | return $this->setHeadersPosition(self::HEADERS_TOP); |
138 | 138 | } |
139 | 139 | |
140 | - /** |
|
141 | - * Specifies that headers are positioned on the left, vertically. |
|
142 | - * @return CSVHelper |
|
143 | - */ |
|
140 | + /** |
|
141 | + * Specifies that headers are positioned on the left, vertically. |
|
142 | + * @return CSVHelper |
|
143 | + */ |
|
144 | 144 | public function setHeadersLeft() |
145 | 145 | { |
146 | 146 | return $this->setHeadersPosition(self::HEADERS_LEFT); |
147 | 147 | } |
148 | 148 | |
149 | - /** |
|
150 | - * Specifies that there are no headers in the file (default). |
|
151 | - * @return CSVHelper |
|
152 | - */ |
|
149 | + /** |
|
150 | + * Specifies that there are no headers in the file (default). |
|
151 | + * @return CSVHelper |
|
152 | + */ |
|
153 | 153 | public function setHeadersNone() |
154 | 154 | { |
155 | 155 | return $this->setHeadersPosition(self::HEADERS_NONE); |
@@ -179,18 +179,18 @@ discard block |
||
179 | 179 | return false; |
180 | 180 | } |
181 | 181 | |
182 | - /** |
|
183 | - * Specifies where the headers are positioned in the |
|
184 | - * CSV, or turns them off entirely. Use the class constants |
|
185 | - * to ensure the value is correct. |
|
186 | - * |
|
187 | - * @param string $position |
|
188 | - * @throws CSVHelper_Exception |
|
189 | - * @return CSVHelper |
|
190 | - * @see CSVHelper::HEADERS_LEFT |
|
191 | - * @see CSVHelper::HEADERS_TOP |
|
192 | - * @see CSVHelper::HEADERS_NONE |
|
193 | - */ |
|
182 | + /** |
|
183 | + * Specifies where the headers are positioned in the |
|
184 | + * CSV, or turns them off entirely. Use the class constants |
|
185 | + * to ensure the value is correct. |
|
186 | + * |
|
187 | + * @param string $position |
|
188 | + * @throws CSVHelper_Exception |
|
189 | + * @return CSVHelper |
|
190 | + * @see CSVHelper::HEADERS_LEFT |
|
191 | + * @see CSVHelper::HEADERS_TOP |
|
192 | + * @see CSVHelper::HEADERS_NONE |
|
193 | + */ |
|
194 | 194 | public function setHeadersPosition($position) |
195 | 195 | { |
196 | 196 | $validPositions = array( |
@@ -217,13 +217,13 @@ discard block |
||
217 | 217 | return $this; |
218 | 218 | } |
219 | 219 | |
220 | - /** |
|
221 | - * Resets all internal data, allowing to start entirely anew |
|
222 | - * with a new file, or to start building a new CSV file from |
|
223 | - * scratch. |
|
224 | - * |
|
225 | - * @return CSVHelper |
|
226 | - */ |
|
220 | + /** |
|
221 | + * Resets all internal data, allowing to start entirely anew |
|
222 | + * with a new file, or to start building a new CSV file from |
|
223 | + * scratch. |
|
224 | + * |
|
225 | + * @return CSVHelper |
|
226 | + */ |
|
227 | 227 | public function reset() |
228 | 228 | { |
229 | 229 | $this->data = array(); |
@@ -240,19 +240,19 @@ discard block |
||
240 | 240 | return $this->data; |
241 | 241 | } |
242 | 242 | |
243 | - /** |
|
244 | - * Retrieves the row at the specified index. |
|
245 | - * If there is no data at the index, this will |
|
246 | - * return an array populated with empty strings |
|
247 | - * for all available columns. |
|
248 | - * |
|
249 | - * Tip: Use the {@link rowExists()} method to check |
|
250 | - * whether the specified row exists. |
|
251 | - * |
|
252 | - * @param integer $index |
|
253 | - * @return array() |
|
254 | - * @see rowExists() |
|
255 | - */ |
|
243 | + /** |
|
244 | + * Retrieves the row at the specified index. |
|
245 | + * If there is no data at the index, this will |
|
246 | + * return an array populated with empty strings |
|
247 | + * for all available columns. |
|
248 | + * |
|
249 | + * Tip: Use the {@link rowExists()} method to check |
|
250 | + * whether the specified row exists. |
|
251 | + * |
|
252 | + * @param integer $index |
|
253 | + * @return array() |
|
254 | + * @see rowExists() |
|
255 | + */ |
|
256 | 256 | public function getRow($index) |
257 | 257 | { |
258 | 258 | if(isset($this->data[$index])) { |
@@ -262,63 +262,63 @@ discard block |
||
262 | 262 | return array_fill(0, $this->rowCount, ''); |
263 | 263 | } |
264 | 264 | |
265 | - /** |
|
266 | - * Checks whether the specified row exists in the data set. |
|
267 | - * @param integer $index |
|
268 | - * @return boolean |
|
269 | - */ |
|
265 | + /** |
|
266 | + * Checks whether the specified row exists in the data set. |
|
267 | + * @param integer $index |
|
268 | + * @return boolean |
|
269 | + */ |
|
270 | 270 | public function rowExists($index) |
271 | 271 | { |
272 | 272 | return isset($this->data[$index]); |
273 | 273 | } |
274 | 274 | |
275 | - /** |
|
276 | - * Counts the amount of rows in the parsed CSV, |
|
277 | - * excluding the headers if any, depending on |
|
278 | - * their position. |
|
279 | - * |
|
280 | - * @return integer |
|
281 | - */ |
|
275 | + /** |
|
276 | + * Counts the amount of rows in the parsed CSV, |
|
277 | + * excluding the headers if any, depending on |
|
278 | + * their position. |
|
279 | + * |
|
280 | + * @return integer |
|
281 | + */ |
|
282 | 282 | public function countRows() |
283 | 283 | { |
284 | 284 | return $this->rowCount; |
285 | 285 | } |
286 | 286 | |
287 | - /** |
|
288 | - * Counts the amount of rows in the parsed CSV, |
|
289 | - * excluding the headers if any, depending on |
|
290 | - * their position. |
|
291 | - * |
|
292 | - * @return integer |
|
293 | - */ |
|
287 | + /** |
|
288 | + * Counts the amount of rows in the parsed CSV, |
|
289 | + * excluding the headers if any, depending on |
|
290 | + * their position. |
|
291 | + * |
|
292 | + * @return integer |
|
293 | + */ |
|
294 | 294 | public function countColumns() |
295 | 295 | { |
296 | 296 | return $this->columnCount; |
297 | 297 | } |
298 | 298 | |
299 | - /** |
|
300 | - * Retrieves the headers, if any. Specify the position of the |
|
301 | - * headers first to ensure this works correctly. |
|
302 | - * |
|
303 | - * @return array Indexed array with header names. |
|
304 | - */ |
|
299 | + /** |
|
300 | + * Retrieves the headers, if any. Specify the position of the |
|
301 | + * headers first to ensure this works correctly. |
|
302 | + * |
|
303 | + * @return array Indexed array with header names. |
|
304 | + */ |
|
305 | 305 | public function getHeaders() |
306 | 306 | { |
307 | 307 | return $this->headers; |
308 | 308 | } |
309 | 309 | |
310 | - /** |
|
311 | - * Retrieves the column at the specified index. If there |
|
312 | - * is no column at the index, this returns an array |
|
313 | - * populated with empty strings. |
|
314 | - * |
|
315 | - * Tip: Use the {@link columnExists()} method to check |
|
316 | - * whether a column exists. |
|
317 | - * |
|
318 | - * @param integer $index |
|
319 | - * @return string[] |
|
320 | - * @see columnExists() |
|
321 | - */ |
|
310 | + /** |
|
311 | + * Retrieves the column at the specified index. If there |
|
312 | + * is no column at the index, this returns an array |
|
313 | + * populated with empty strings. |
|
314 | + * |
|
315 | + * Tip: Use the {@link columnExists()} method to check |
|
316 | + * whether a column exists. |
|
317 | + * |
|
318 | + * @param integer $index |
|
319 | + * @return string[] |
|
320 | + * @see columnExists() |
|
321 | + */ |
|
322 | 322 | public function getColumn($index) |
323 | 323 | { |
324 | 324 | $data = array(); |
@@ -334,11 +334,11 @@ discard block |
||
334 | 334 | return $data; |
335 | 335 | } |
336 | 336 | |
337 | - /** |
|
338 | - * Checks whether the specified column exists in the data set. |
|
339 | - * @param integer $index |
|
340 | - * @return boolean |
|
341 | - */ |
|
337 | + /** |
|
338 | + * Checks whether the specified column exists in the data set. |
|
339 | + * @param integer $index |
|
340 | + * @return boolean |
|
341 | + */ |
|
342 | 342 | public function columnExists($index) |
343 | 343 | { |
344 | 344 | if($index < $this->columnCount) { |
@@ -402,22 +402,22 @@ discard block |
||
402 | 402 | } |
403 | 403 | } |
404 | 404 | |
405 | - /** |
|
406 | - * Checks whether any errors have been encountered |
|
407 | - * while parsing the CSV. |
|
408 | - * |
|
409 | - * @return boolean |
|
410 | - * @see getErrorMessages() |
|
411 | - */ |
|
405 | + /** |
|
406 | + * Checks whether any errors have been encountered |
|
407 | + * while parsing the CSV. |
|
408 | + * |
|
409 | + * @return boolean |
|
410 | + * @see getErrorMessages() |
|
411 | + */ |
|
412 | 412 | public function hasErrors() |
413 | 413 | { |
414 | 414 | return !empty($this->errors); |
415 | 415 | } |
416 | 416 | |
417 | - /** |
|
418 | - * Retrieves all error messages. |
|
419 | - * @return array |
|
420 | - */ |
|
417 | + /** |
|
418 | + * Retrieves all error messages. |
|
419 | + * @return array |
|
420 | + */ |
|
421 | 421 | public function getErrorMessages() |
422 | 422 | { |
423 | 423 | return $this->errors; |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | public function loadFile($file) |
109 | 109 | { |
110 | 110 | $csv = file_get_contents($file); |
111 | - if(!$csv) { |
|
111 | + if (!$csv) { |
|
112 | 112 | throw new CSVHelper_Exception( |
113 | 113 | 'Cannot read csv file', |
114 | 114 | sprintf( |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | |
173 | 173 | public function isHeadersPosition($position) |
174 | 174 | { |
175 | - if($this->headersPosition === $position) { |
|
175 | + if ($this->headersPosition === $position) { |
|
176 | 176 | return true; |
177 | 177 | } |
178 | 178 | |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | self::HEADERS_TOP |
200 | 200 | ); |
201 | 201 | |
202 | - if(!in_array($position, $validPositions)) { |
|
202 | + if (!in_array($position, $validPositions)) { |
|
203 | 203 | throw new CSVHelper_Exception( |
204 | 204 | 'Invalid headers position', |
205 | 205 | sprintf( |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | */ |
256 | 256 | public function getRow($index) |
257 | 257 | { |
258 | - if(isset($this->data[$index])) { |
|
258 | + if (isset($this->data[$index])) { |
|
259 | 259 | return $this->data[$index]; |
260 | 260 | } |
261 | 261 | |
@@ -322,9 +322,9 @@ discard block |
||
322 | 322 | public function getColumn($index) |
323 | 323 | { |
324 | 324 | $data = array(); |
325 | - for($i=0; $i < $this->rowCount; $i++) { |
|
325 | + for ($i = 0; $i < $this->rowCount; $i++) { |
|
326 | 326 | $value = ''; |
327 | - if(isset($this->data[$i][$index])) { |
|
327 | + if (isset($this->data[$i][$index])) { |
|
328 | 328 | $value = $this->data[$i][$index]; |
329 | 329 | } |
330 | 330 | |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | */ |
342 | 342 | public function columnExists($index) |
343 | 343 | { |
344 | - if($index < $this->columnCount) { |
|
344 | + if ($index < $this->columnCount) { |
|
345 | 345 | return true; |
346 | 346 | } |
347 | 347 | |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | { |
353 | 353 | $this->reset(); |
354 | 354 | |
355 | - if(empty(trim($this->csv))) { |
|
355 | + if (empty(trim($this->csv))) { |
|
356 | 356 | $this->addError('Tried to parse an empty CSV string.'); |
357 | 357 | return; |
358 | 358 | } |
@@ -367,12 +367,12 @@ discard block |
||
367 | 367 | $parser->delimiter = $this->detectSeparator(); |
368 | 368 | |
369 | 369 | $result = $parser->parse_string($this->csv); |
370 | - if(!$result) { |
|
370 | + if (!$result) { |
|
371 | 371 | $this->addError('The CSV string could not be parsed.'); |
372 | 372 | return; |
373 | 373 | } |
374 | 374 | |
375 | - switch($this->headersPosition) |
|
375 | + switch ($this->headersPosition) |
|
376 | 376 | { |
377 | 377 | case self::HEADERS_TOP: |
378 | 378 | $this->headers = array_shift($result); |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | case self::HEADERS_LEFT: |
382 | 382 | $keep = array(); |
383 | 383 | $total = count($result); |
384 | - for($i=0; $i < $total; $i++) { |
|
384 | + for ($i = 0; $i < $total; $i++) { |
|
385 | 385 | $row = $result[$i]; |
386 | 386 | $this->headers[] = array_shift($row); |
387 | 387 | $keep[] = $row; |
@@ -394,9 +394,9 @@ discard block |
||
394 | 394 | $this->data = $result; |
395 | 395 | $this->rowCount = count($this->data); |
396 | 396 | |
397 | - for($i=0; $i < $this->rowCount; $i++) { |
|
397 | + for ($i = 0; $i < $this->rowCount; $i++) { |
|
398 | 398 | $amount = count($this->data[$i]); |
399 | - if($amount > $this->columnCount) { |
|
399 | + if ($amount > $this->columnCount) { |
|
400 | 400 | $this->columnCount = $amount; |
401 | 401 | } |
402 | 402 | } |
@@ -440,8 +440,8 @@ discard block |
||
440 | 440 | ',,' => ',' |
441 | 441 | ); |
442 | 442 | |
443 | - foreach($search as $char => $separator) { |
|
444 | - if(strstr($this->csv, $char)) { |
|
443 | + foreach ($search as $char => $separator) { |
|
444 | + if (strstr($this->csv, $char)) { |
|
445 | 445 | return $separator; |
446 | 446 | } |
447 | 447 | } |
@@ -38,38 +38,38 @@ |
||
38 | 38 | */ |
39 | 39 | protected $text; |
40 | 40 | |
41 | - /** |
|
42 | - * @var string |
|
43 | - */ |
|
41 | + /** |
|
42 | + * @var string |
|
43 | + */ |
|
44 | 44 | protected $trimmed; |
45 | 45 | |
46 | - /** |
|
47 | - * @var int |
|
48 | - */ |
|
46 | + /** |
|
47 | + * @var int |
|
48 | + */ |
|
49 | 49 | protected $lineNumber; |
50 | 50 | |
51 | - /** |
|
52 | - * @var string |
|
53 | - */ |
|
51 | + /** |
|
52 | + * @var string |
|
53 | + */ |
|
54 | 54 | protected $type; |
55 | 55 | |
56 | - /** |
|
57 | - * @var string |
|
58 | - */ |
|
56 | + /** |
|
57 | + * @var string |
|
58 | + */ |
|
59 | 59 | protected $varName = ''; |
60 | 60 | |
61 | - /** |
|
62 | - * @var string |
|
63 | - */ |
|
61 | + /** |
|
62 | + * @var string |
|
63 | + */ |
|
64 | 64 | protected $varValue = ''; |
65 | 65 | |
66 | 66 | protected $valueUnquoted = ''; |
67 | 67 | |
68 | 68 | protected $quoteStyle = ''; |
69 | 69 | |
70 | - /** |
|
71 | - * @var string |
|
72 | - */ |
|
70 | + /** |
|
71 | + * @var string |
|
72 | + */ |
|
73 | 73 | protected $sectionName = ''; |
74 | 74 | |
75 | 75 | public function __construct(string $text, int $lineNumber) |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | $this->trimmed = trim($text); |
79 | 79 | $this->lineNumber = $lineNumber; |
80 | 80 | |
81 | - if(empty($this->trimmed)) |
|
81 | + if (empty($this->trimmed)) |
|
82 | 82 | { |
83 | 83 | $this->type = self::TYPE_EMPTY; |
84 | 84 | return; |
@@ -86,11 +86,11 @@ discard block |
||
86 | 86 | |
87 | 87 | $startChar = substr($this->trimmed, 0, 1); |
88 | 88 | |
89 | - if($startChar === ';') |
|
89 | + if ($startChar === ';') |
|
90 | 90 | { |
91 | 91 | $this->type = self::TYPE_COMMENT; |
92 | 92 | } |
93 | - else if($startChar === '[') |
|
93 | + else if ($startChar === '[') |
|
94 | 94 | { |
95 | 95 | $this->type = self::TYPE_SECTION_DECLARATION; |
96 | 96 | $this->sectionName = trim($this->trimmed, '[]'); |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | else |
100 | 100 | { |
101 | 101 | $pos = strpos($this->trimmed, '='); |
102 | - if($pos === false) |
|
102 | + if ($pos === false) |
|
103 | 103 | { |
104 | 104 | $this->type = self::TYPE_INVALID; |
105 | 105 | return; |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | $this->type = self::TYPE_VALUE; |
109 | 109 | $this->varName = trim(substr($this->trimmed, 0, $pos)); |
110 | 110 | |
111 | - $this->parseValue(substr($this->trimmed, $pos+1)); |
|
111 | + $this->parseValue(substr($this->trimmed, $pos + 1)); |
|
112 | 112 | } |
113 | 113 | } |
114 | 114 | |
@@ -118,12 +118,12 @@ discard block |
||
118 | 118 | |
119 | 119 | $value = $this->varValue; |
120 | 120 | |
121 | - if(substr($value, 0, 1) == '"' && substr($value, -1, 1) == '"') |
|
121 | + if (substr($value, 0, 1) == '"' && substr($value, -1, 1) == '"') |
|
122 | 122 | { |
123 | 123 | $value = trim($value, '"'); |
124 | 124 | $this->quoteStyle = '"'; |
125 | 125 | } |
126 | - else if(substr($value, 0, 1) == "'" && substr($value, -1, 1) == "'") |
|
126 | + else if (substr($value, 0, 1) == "'" && substr($value, -1, 1) == "'") |
|
127 | 127 | { |
128 | 128 | $value = trim($value, "'"); |
129 | 129 | $this->quoteStyle = "'"; |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | |
145 | 145 | public function getQuotedVarValue() : string |
146 | 146 | { |
147 | - if($this->quoteStyle === '') { |
|
147 | + if ($this->quoteStyle === '') { |
|
148 | 148 | return $this->getVarValue(); |
149 | 149 | } |
150 | 150 | |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | |
199 | 199 | public function setValue($value) : IniHelper_Line |
200 | 200 | { |
201 | - if(!is_scalar($value)) |
|
201 | + if (!is_scalar($value)) |
|
202 | 202 | { |
203 | 203 | throw new IniHelper_Exception( |
204 | 204 | 'Cannot use non-scalar values.', |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | |
219 | 219 | public function toString() : string |
220 | 220 | { |
221 | - switch($this->type) |
|
221 | + switch ($this->type) |
|
222 | 222 | { |
223 | 223 | case self::TYPE_EMPTY: |
224 | 224 | case self::TYPE_INVALID: |
@@ -89,14 +89,12 @@ discard block |
||
89 | 89 | if($startChar === ';') |
90 | 90 | { |
91 | 91 | $this->type = self::TYPE_COMMENT; |
92 | - } |
|
93 | - else if($startChar === '[') |
|
92 | + } else if($startChar === '[') |
|
94 | 93 | { |
95 | 94 | $this->type = self::TYPE_SECTION_DECLARATION; |
96 | 95 | $this->sectionName = trim($this->trimmed, '[]'); |
97 | 96 | $this->sectionName = trim($this->sectionName); // remove any whitespace |
98 | - } |
|
99 | - else |
|
97 | + } else |
|
100 | 98 | { |
101 | 99 | $pos = strpos($this->trimmed, '='); |
102 | 100 | if($pos === false) |
@@ -122,8 +120,7 @@ discard block |
||
122 | 120 | { |
123 | 121 | $value = trim($value, '"'); |
124 | 122 | $this->quoteStyle = '"'; |
125 | - } |
|
126 | - else if(substr($value, 0, 1) == "'" && substr($value, -1, 1) == "'") |
|
123 | + } else if(substr($value, 0, 1) == "'" && substr($value, -1, 1) == "'") |
|
127 | 124 | { |
128 | 125 | $value = trim($value, "'"); |
129 | 126 | $this->quoteStyle = "'"; |
@@ -21,19 +21,19 @@ discard block |
||
21 | 21 | */ |
22 | 22 | class IniHelper_Section |
23 | 23 | { |
24 | - /** |
|
25 | - * @var IniHelper |
|
26 | - */ |
|
24 | + /** |
|
25 | + * @var IniHelper |
|
26 | + */ |
|
27 | 27 | protected $ini; |
28 | 28 | |
29 | - /** |
|
30 | - * @var string |
|
31 | - */ |
|
29 | + /** |
|
30 | + * @var string |
|
31 | + */ |
|
32 | 32 | protected $name; |
33 | 33 | |
34 | - /** |
|
35 | - * @var IniHelper_Line[] |
|
36 | - */ |
|
34 | + /** |
|
35 | + * @var IniHelper_Line[] |
|
36 | + */ |
|
37 | 37 | protected $lines = array(); |
38 | 38 | |
39 | 39 | public function __construct(IniHelper $ini, string $name) |
@@ -42,33 +42,33 @@ discard block |
||
42 | 42 | $this->name = $name; |
43 | 43 | } |
44 | 44 | |
45 | - /** |
|
46 | - * The section's name. |
|
47 | - * @return string |
|
48 | - */ |
|
45 | + /** |
|
46 | + * The section's name. |
|
47 | + * @return string |
|
48 | + */ |
|
49 | 49 | public function getName() : string |
50 | 50 | { |
51 | 51 | return $this->name; |
52 | 52 | } |
53 | 53 | |
54 | - /** |
|
55 | - * Whether this is the default section: this |
|
56 | - * is used internally to store all variables that |
|
57 | - * are not in any specific section. |
|
58 | - * |
|
59 | - * @return bool |
|
60 | - */ |
|
54 | + /** |
|
55 | + * Whether this is the default section: this |
|
56 | + * is used internally to store all variables that |
|
57 | + * are not in any specific section. |
|
58 | + * |
|
59 | + * @return bool |
|
60 | + */ |
|
61 | 61 | public function isDefault() : bool |
62 | 62 | { |
63 | 63 | return $this->name === IniHelper::SECTION_DEFAULT; |
64 | 64 | } |
65 | 65 | |
66 | - /** |
|
67 | - * Adds a line instance to the section. |
|
68 | - * |
|
69 | - * @param IniHelper_Line $line |
|
70 | - * @return IniHelper_Section |
|
71 | - */ |
|
66 | + /** |
|
67 | + * Adds a line instance to the section. |
|
68 | + * |
|
69 | + * @param IniHelper_Line $line |
|
70 | + * @return IniHelper_Section |
|
71 | + */ |
|
72 | 72 | public function addLine(IniHelper_Line $line) : IniHelper_Section |
73 | 73 | { |
74 | 74 | $this->lines[] = $line; |
@@ -76,12 +76,12 @@ discard block |
||
76 | 76 | return $this; |
77 | 77 | } |
78 | 78 | |
79 | - /** |
|
80 | - * Converts the values contained in the section into |
|
81 | - * an associative array. |
|
82 | - * |
|
83 | - * @return array |
|
84 | - */ |
|
79 | + /** |
|
80 | + * Converts the values contained in the section into |
|
81 | + * an associative array. |
|
82 | + * |
|
83 | + * @return array |
|
84 | + */ |
|
85 | 85 | public function toArray() : array |
86 | 86 | { |
87 | 87 | $result = array(); |
@@ -114,11 +114,11 @@ discard block |
||
114 | 114 | return $result; |
115 | 115 | } |
116 | 116 | |
117 | - /** |
|
118 | - * Converts the section's lines into an INI string. |
|
119 | - * |
|
120 | - * @return string |
|
121 | - */ |
|
117 | + /** |
|
118 | + * Converts the section's lines into an INI string. |
|
119 | + * |
|
120 | + * @return string |
|
121 | + */ |
|
122 | 122 | public function toString() |
123 | 123 | { |
124 | 124 | $lines = array(); |
@@ -140,12 +140,12 @@ discard block |
||
140 | 140 | return implode($this->ini->getEOLChar(), $lines); |
141 | 141 | } |
142 | 142 | |
143 | - /** |
|
144 | - * Deletes a line from the section. |
|
145 | - * |
|
146 | - * @param IniHelper_Line $toDelete |
|
147 | - * @return IniHelper_Section |
|
148 | - */ |
|
143 | + /** |
|
144 | + * Deletes a line from the section. |
|
145 | + * |
|
146 | + * @param IniHelper_Line $toDelete |
|
147 | + * @return IniHelper_Section |
|
148 | + */ |
|
149 | 149 | public function deleteLine(IniHelper_Line $toDelete) : IniHelper_Section |
150 | 150 | { |
151 | 151 | $keep = array(); |
@@ -162,13 +162,13 @@ discard block |
||
162 | 162 | return $this; |
163 | 163 | } |
164 | 164 | |
165 | - /** |
|
166 | - * Sets the value of a variable, overwriting any existing value. |
|
167 | - * |
|
168 | - * @param string $name |
|
169 | - * @param mixed $value If an array is specified, it is treated as duplicate keys and will add a line for each value. |
|
170 | - * @return IniHelper_Section |
|
171 | - */ |
|
165 | + /** |
|
166 | + * Sets the value of a variable, overwriting any existing value. |
|
167 | + * |
|
168 | + * @param string $name |
|
169 | + * @param mixed $value If an array is specified, it is treated as duplicate keys and will add a line for each value. |
|
170 | + * @return IniHelper_Section |
|
171 | + */ |
|
172 | 172 | public function setValue(string $name, $value) : IniHelper_Section |
173 | 173 | { |
174 | 174 | $lines = $this->getLinesByVariable($name); |
@@ -229,15 +229,15 @@ discard block |
||
229 | 229 | return $this; |
230 | 230 | } |
231 | 231 | |
232 | - /** |
|
233 | - * Adds a variable value to the section. Unlike setValue(), this |
|
234 | - * will not overwrite any existing value. If the name is an existing |
|
235 | - * variable name, it will be converted to duplicate keys. |
|
236 | - * |
|
237 | - * @param string $name |
|
238 | - * @param mixed $value If this is an array, it will be treated as duplicate keys, and all values that are not present yet will be added. |
|
239 | - * @return IniHelper_Section |
|
240 | - */ |
|
232 | + /** |
|
233 | + * Adds a variable value to the section. Unlike setValue(), this |
|
234 | + * will not overwrite any existing value. If the name is an existing |
|
235 | + * variable name, it will be converted to duplicate keys. |
|
236 | + * |
|
237 | + * @param string $name |
|
238 | + * @param mixed $value If this is an array, it will be treated as duplicate keys, and all values that are not present yet will be added. |
|
239 | + * @return IniHelper_Section |
|
240 | + */ |
|
241 | 241 | public function addValue(string $name, $value) : IniHelper_Section |
242 | 242 | { |
243 | 243 | // array value? Treat it as duplicate keys. |
@@ -295,12 +295,12 @@ discard block |
||
295 | 295 | } |
296 | 296 | |
297 | 297 | |
298 | - /** |
|
299 | - * Retrieves all lines for the specified variable name. |
|
300 | - * |
|
301 | - * @param string $name |
|
302 | - * @return \AppUtils\IniHelper_Line[] |
|
303 | - */ |
|
298 | + /** |
|
299 | + * Retrieves all lines for the specified variable name. |
|
300 | + * |
|
301 | + * @param string $name |
|
302 | + * @return \AppUtils\IniHelper_Line[] |
|
303 | + */ |
|
304 | 304 | public function getLinesByVariable(string $name) |
305 | 305 | { |
306 | 306 | $result = array(); |
@@ -86,15 +86,15 @@ discard block |
||
86 | 86 | { |
87 | 87 | $result = array(); |
88 | 88 | |
89 | - foreach($this->lines as $line) |
|
89 | + foreach ($this->lines as $line) |
|
90 | 90 | { |
91 | - if(!$line->isValue()) { |
|
91 | + if (!$line->isValue()) { |
|
92 | 92 | continue; |
93 | 93 | } |
94 | 94 | |
95 | 95 | $name = $line->getVarName(); |
96 | 96 | |
97 | - if(!isset($result[$name])) |
|
97 | + if (!isset($result[$name])) |
|
98 | 98 | { |
99 | 99 | $result[$name] = $line->getVarValue(); |
100 | 100 | continue; |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | // name exists in collection? Then this is a |
104 | 104 | // duplicate key and we need to convert it to |
105 | 105 | // an indexed array of values. |
106 | - if(!is_array($result[$name])) |
|
106 | + if (!is_array($result[$name])) |
|
107 | 107 | { |
108 | 108 | $result[$name] = array($result[$name]); |
109 | 109 | } |
@@ -122,15 +122,15 @@ discard block |
||
122 | 122 | public function toString() |
123 | 123 | { |
124 | 124 | $lines = array(); |
125 | - if(!$this->isDefault()) |
|
125 | + if (!$this->isDefault()) |
|
126 | 126 | { |
127 | 127 | $lines[] = '['.$this->getName().']'; |
128 | 128 | } |
129 | 129 | |
130 | - foreach($this->lines as $line) |
|
130 | + foreach ($this->lines as $line) |
|
131 | 131 | { |
132 | 132 | // we already did this |
133 | - if($line->isSection()) { |
|
133 | + if ($line->isSection()) { |
|
134 | 134 | continue; |
135 | 135 | } |
136 | 136 | |
@@ -150,9 +150,9 @@ discard block |
||
150 | 150 | { |
151 | 151 | $keep = array(); |
152 | 152 | |
153 | - foreach($this->lines as $line) |
|
153 | + foreach ($this->lines as $line) |
|
154 | 154 | { |
155 | - if($line !== $toDelete) { |
|
155 | + if ($line !== $toDelete) { |
|
156 | 156 | $keep[] = $line; |
157 | 157 | } |
158 | 158 | } |
@@ -177,23 +177,23 @@ discard block |
||
177 | 177 | // Removes any superfluous values that may |
178 | 178 | // already exist, if there are more than the |
179 | 179 | // new set of values. |
180 | - if(is_array($value)) |
|
180 | + if (is_array($value)) |
|
181 | 181 | { |
182 | 182 | $values = array_values($value); |
183 | 183 | $amountNew = count($values); |
184 | 184 | $amountExisting = count($lines); |
185 | 185 | |
186 | 186 | $max = $amountNew; |
187 | - if($amountExisting > $max) { |
|
187 | + if ($amountExisting > $max) { |
|
188 | 188 | $max = $amountExisting; |
189 | 189 | } |
190 | 190 | |
191 | - for($i=0; $i < $max; $i++) |
|
191 | + for ($i = 0; $i < $max; $i++) |
|
192 | 192 | { |
193 | 193 | // new value exists |
194 | - if(isset($values[$i])) |
|
194 | + if (isset($values[$i])) |
|
195 | 195 | { |
196 | - if(isset($lines[$i])) { |
|
196 | + if (isset($lines[$i])) { |
|
197 | 197 | $lines[$i]->setValue($values[$i]); |
198 | 198 | } else { |
199 | 199 | $this->addValueLine($name, $values[$i]); |
@@ -211,12 +211,12 @@ discard block |
||
211 | 211 | else |
212 | 212 | { |
213 | 213 | // remove all superfluous lines |
214 | - if(!empty($lines)) |
|
214 | + if (!empty($lines)) |
|
215 | 215 | { |
216 | 216 | $line = array_shift($lines); // keep only the first line |
217 | 217 | $line->setValue($value); |
218 | 218 | |
219 | - foreach($lines as $delete) { |
|
219 | + foreach ($lines as $delete) { |
|
220 | 220 | $this->deleteLine($delete); |
221 | 221 | } |
222 | 222 | } |
@@ -241,11 +241,11 @@ discard block |
||
241 | 241 | public function addValue(string $name, $value) : IniHelper_Section |
242 | 242 | { |
243 | 243 | // array value? Treat it as duplicate keys. |
244 | - if(is_array($value)) |
|
244 | + if (is_array($value)) |
|
245 | 245 | { |
246 | 246 | $values = array_values($value); |
247 | 247 | |
248 | - foreach($values as $setValue) |
|
248 | + foreach ($values as $setValue) |
|
249 | 249 | { |
250 | 250 | $this->addValue($name, $setValue); |
251 | 251 | } |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | |
256 | 256 | $lines = $this->getLinesByVariable($name); |
257 | 257 | |
258 | - if(empty($lines)) |
|
258 | + if (empty($lines)) |
|
259 | 259 | { |
260 | 260 | $this->addValueLine($name, $value); |
261 | 261 | } |
@@ -263,15 +263,15 @@ discard block |
||
263 | 263 | { |
264 | 264 | $found = false; |
265 | 265 | |
266 | - foreach($lines as $line) |
|
266 | + foreach ($lines as $line) |
|
267 | 267 | { |
268 | - if($line->getVarValue() === $value) { |
|
268 | + if ($line->getVarValue() === $value) { |
|
269 | 269 | $found = $line; |
270 | 270 | break; |
271 | 271 | } |
272 | 272 | } |
273 | 273 | |
274 | - if(!$found) |
|
274 | + if (!$found) |
|
275 | 275 | { |
276 | 276 | $this->addValueLine($name, $value); |
277 | 277 | } |
@@ -305,9 +305,9 @@ discard block |
||
305 | 305 | { |
306 | 306 | $result = array(); |
307 | 307 | |
308 | - foreach($this->lines as $line) |
|
308 | + foreach ($this->lines as $line) |
|
309 | 309 | { |
310 | - if($line->isValue() && $line->getVarName() === $name) { |
|
310 | + if ($line->isValue() && $line->getVarName() === $name) { |
|
311 | 311 | $result[] = $line; |
312 | 312 | } |
313 | 313 | } |
@@ -198,8 +198,7 @@ discard block |
||
198 | 198 | } else { |
199 | 199 | $this->addValueLine($name, $values[$i]); |
200 | 200 | } |
201 | - } |
|
202 | - else |
|
201 | + } else |
|
203 | 202 | { |
204 | 203 | $this->deleteLine($lines[$i]); |
205 | 204 | } |
@@ -219,8 +218,7 @@ discard block |
||
219 | 218 | foreach($lines as $delete) { |
220 | 219 | $this->deleteLine($delete); |
221 | 220 | } |
222 | - } |
|
223 | - else |
|
221 | + } else |
|
224 | 222 | { |
225 | 223 | $this->addValueLine($name, $value); |
226 | 224 | } |
@@ -258,8 +256,7 @@ discard block |
||
258 | 256 | if(empty($lines)) |
259 | 257 | { |
260 | 258 | $this->addValueLine($name, $value); |
261 | - } |
|
262 | - else |
|
259 | + } else |
|
263 | 260 | { |
264 | 261 | $found = false; |
265 | 262 |
@@ -38,9 +38,9 @@ discard block |
||
38 | 38 | |
39 | 39 | protected $file; |
40 | 40 | |
41 | - /** |
|
42 | - * @var \ZipArchive |
|
43 | - */ |
|
41 | + /** |
|
42 | + * @var \ZipArchive |
|
43 | + */ |
|
44 | 44 | protected $zip; |
45 | 45 | |
46 | 46 | public function __construct($targetFile) |
@@ -48,33 +48,33 @@ discard block |
||
48 | 48 | $this->file = $targetFile; |
49 | 49 | } |
50 | 50 | |
51 | - /** |
|
52 | - * Sets an option, among the available options: |
|
53 | - * |
|
54 | - * <ul> |
|
55 | - * <li>WriteThreshold: The amount of files to add before the zip is automatically written to disk and re-opened to release the file handles. Set to 0 to disable.</li> |
|
56 | - * </ul> |
|
57 | - * |
|
58 | - * @param string $name |
|
59 | - * @param mixed $value |
|
60 | - * @return ZIPHelper |
|
61 | - */ |
|
51 | + /** |
|
52 | + * Sets an option, among the available options: |
|
53 | + * |
|
54 | + * <ul> |
|
55 | + * <li>WriteThreshold: The amount of files to add before the zip is automatically written to disk and re-opened to release the file handles. Set to 0 to disable.</li> |
|
56 | + * </ul> |
|
57 | + * |
|
58 | + * @param string $name |
|
59 | + * @param mixed $value |
|
60 | + * @return ZIPHelper |
|
61 | + */ |
|
62 | 62 | public function setOption($name, $value) |
63 | 63 | { |
64 | 64 | $this->options[$name] = $value; |
65 | 65 | return $this; |
66 | 66 | } |
67 | 67 | |
68 | - /** |
|
69 | - * Adds a file to the zip. By default, the file is stored |
|
70 | - * with the same name in the root of the zip. Use the optional |
|
71 | - * parameter to change the location in the zip. |
|
72 | - * |
|
73 | - * @param string $filePath |
|
74 | - * @param string $zipPath |
|
75 | - * @throws ZIPHelper_Exception |
|
76 | - * @return bool |
|
77 | - */ |
|
68 | + /** |
|
69 | + * Adds a file to the zip. By default, the file is stored |
|
70 | + * with the same name in the root of the zip. Use the optional |
|
71 | + * parameter to change the location in the zip. |
|
72 | + * |
|
73 | + * @param string $filePath |
|
74 | + * @param string $zipPath |
|
75 | + * @throws ZIPHelper_Exception |
|
76 | + * @return bool |
|
77 | + */ |
|
78 | 78 | public function addFile($filePath, $zipPath=null) |
79 | 79 | { |
80 | 80 | $this->open(); |
@@ -252,13 +252,13 @@ discard block |
||
252 | 252 | |
253 | 253 | protected $exit; |
254 | 254 | |
255 | - /** |
|
256 | - * Like {@link ZIPHelper::download()}, but deletes the |
|
257 | - * file after sending it to the browser. |
|
258 | - * |
|
259 | - * @param string|NULL $fileName Override the ZIP's file name for the download |
|
260 | - * @see ZIPHelper::download() |
|
261 | - */ |
|
255 | + /** |
|
256 | + * Like {@link ZIPHelper::download()}, but deletes the |
|
257 | + * file after sending it to the browser. |
|
258 | + * |
|
259 | + * @param string|NULL $fileName Override the ZIP's file name for the download |
|
260 | + * @see ZIPHelper::download() |
|
261 | + */ |
|
262 | 262 | public function downloadAndDelete($fileName=null) |
263 | 263 | { |
264 | 264 | $this->exit = false; |
@@ -272,14 +272,14 @@ discard block |
||
272 | 272 | exit; |
273 | 273 | } |
274 | 274 | |
275 | - /** |
|
276 | - * Extracts all files and folders from the zip to the |
|
277 | - * target folder. If no folder is specified, the files |
|
278 | - * are extracted into the same folder as the zip itself. |
|
279 | - * |
|
280 | - * @param string $outputFolder |
|
281 | - * @return boolean |
|
282 | - */ |
|
275 | + /** |
|
276 | + * Extracts all files and folders from the zip to the |
|
277 | + * target folder. If no folder is specified, the files |
|
278 | + * are extracted into the same folder as the zip itself. |
|
279 | + * |
|
280 | + * @param string $outputFolder |
|
281 | + * @return boolean |
|
282 | + */ |
|
283 | 283 | public function extractAll($outputFolder=null) |
284 | 284 | { |
285 | 285 | if(empty($outputFolder)) { |
@@ -292,9 +292,9 @@ discard block |
||
292 | 292 | } |
293 | 293 | |
294 | 294 | |
295 | - /** |
|
296 | - * @return \ZipArchive |
|
297 | - */ |
|
295 | + /** |
|
296 | + * @return \ZipArchive |
|
297 | + */ |
|
298 | 298 | public function getArchive() |
299 | 299 | { |
300 | 300 | $this->open(); |
@@ -302,14 +302,14 @@ discard block |
||
302 | 302 | return $this->zip; |
303 | 303 | } |
304 | 304 | |
305 | - /** |
|
306 | - * JSON encodes the specified data and adds the json as |
|
307 | - * a file in the ZIP archive. |
|
308 | - * |
|
309 | - * @param mixed $data |
|
310 | - * @param string $zipPath |
|
311 | - * @return boolean |
|
312 | - */ |
|
305 | + /** |
|
306 | + * JSON encodes the specified data and adds the json as |
|
307 | + * a file in the ZIP archive. |
|
308 | + * |
|
309 | + * @param mixed $data |
|
310 | + * @param string $zipPath |
|
311 | + * @return boolean |
|
312 | + */ |
|
313 | 313 | public function addJSON($data, $zipPath) |
314 | 314 | { |
315 | 315 | return $this->addString( |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | |
31 | 31 | const ERROR_OPENING_ZIP_FILE = 338003; |
32 | 32 | |
33 | - const ERROR_CANNOT_SAVE_FILE_TO_DISK =338004; |
|
33 | + const ERROR_CANNOT_SAVE_FILE_TO_DISK = 338004; |
|
34 | 34 | |
35 | 35 | protected $options = array( |
36 | 36 | 'WriteThreshold' => 100 |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * @throws ZIPHelper_Exception |
76 | 76 | * @return bool |
77 | 77 | */ |
78 | - public function addFile($filePath, $zipPath=null) |
|
78 | + public function addFile($filePath, $zipPath = null) |
|
79 | 79 | { |
80 | 80 | $this->open(); |
81 | 81 | |
@@ -120,16 +120,16 @@ discard block |
||
120 | 120 | |
121 | 121 | protected function open() |
122 | 122 | { |
123 | - if($this->open) { |
|
123 | + if ($this->open) { |
|
124 | 124 | return; |
125 | 125 | } |
126 | 126 | |
127 | - if(!isset($this->zip)) { |
|
127 | + if (!isset($this->zip)) { |
|
128 | 128 | $this->zip = new \ZipArchive(); |
129 | 129 | } |
130 | 130 | |
131 | 131 | $flag = null; |
132 | - if(!file_exists($this->file)) { |
|
132 | + if (!file_exists($this->file)) { |
|
133 | 133 | $flag = \ZipArchive::CREATE; |
134 | 134 | } |
135 | 135 | |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | { |
170 | 170 | $this->fileTracker++; |
171 | 171 | |
172 | - if($this->options['WriteThreshold'] < 1) { |
|
172 | + if ($this->options['WriteThreshold'] < 1) { |
|
173 | 173 | return; |
174 | 174 | } |
175 | 175 | |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | |
183 | 183 | protected function close() |
184 | 184 | { |
185 | - if(!$this->open) { |
|
185 | + if (!$this->open) { |
|
186 | 186 | return; |
187 | 187 | } |
188 | 188 | |
@@ -190,8 +190,8 @@ discard block |
||
190 | 190 | throw new ZIPHelper_Exception( |
191 | 191 | 'Could not save ZIP file to disk', |
192 | 192 | sprintf( |
193 | - 'Tried saving the ZIP file [%1$s], but the write failed. This can have several causes, ' . |
|
194 | - 'including adding files that do not exist on disk, trying to create an empty zip, ' . |
|
193 | + 'Tried saving the ZIP file [%1$s], but the write failed. This can have several causes, '. |
|
194 | + 'including adding files that do not exist on disk, trying to create an empty zip, '. |
|
195 | 195 | 'or trying to save to a directory that does not exist.', |
196 | 196 | $this->file |
197 | 197 | ), |
@@ -228,22 +228,22 @@ discard block |
||
228 | 228 | * @see ZIPHelper::downloadAndDelete() |
229 | 229 | * @throws ZIPHelper_Exception |
230 | 230 | */ |
231 | - public function download($fileName=null) |
|
231 | + public function download($fileName = null) |
|
232 | 232 | { |
233 | 233 | $this->save(); |
234 | 234 | |
235 | - if(empty($fileName)) { |
|
235 | + if (empty($fileName)) { |
|
236 | 236 | $fileName = basename($this->file); |
237 | 237 | } |
238 | 238 | |
239 | 239 | header('Content-type: application/zip'); |
240 | - header('Content-Disposition: attachment; filename=' . $fileName); |
|
241 | - header('Content-length: ' . filesize($this->file)); |
|
240 | + header('Content-Disposition: attachment; filename='.$fileName); |
|
241 | + header('Content-length: '.filesize($this->file)); |
|
242 | 242 | header('Pragma: no-cache'); |
243 | 243 | header('Expires: 0'); |
244 | 244 | readfile($this->file); |
245 | 245 | |
246 | - if($this->exit === false) { |
|
246 | + if ($this->exit === false) { |
|
247 | 247 | return; |
248 | 248 | } |
249 | 249 | |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | * @param string|NULL $fileName Override the ZIP's file name for the download |
260 | 260 | * @see ZIPHelper::download() |
261 | 261 | */ |
262 | - public function downloadAndDelete($fileName=null) |
|
262 | + public function downloadAndDelete($fileName = null) |
|
263 | 263 | { |
264 | 264 | $this->exit = false; |
265 | 265 | |
@@ -280,9 +280,9 @@ discard block |
||
280 | 280 | * @param string $outputFolder |
281 | 281 | * @return boolean |
282 | 282 | */ |
283 | - public function extractAll($outputFolder=null) |
|
283 | + public function extractAll($outputFolder = null) |
|
284 | 284 | { |
285 | - if(empty($outputFolder)) { |
|
285 | + if (empty($outputFolder)) { |
|
286 | 286 | $outputFolder = dirname($this->file); |
287 | 287 | } |
288 | 288 |