@@ -37,14 +37,14 @@ discard block |
||
37 | 37 | const TOKEN_MONTHS = 'm'; |
38 | 38 | const TOKEN_YEARS = 'y'; |
39 | 39 | |
40 | - /** |
|
41 | - * @var \DateInterval |
|
42 | - */ |
|
40 | + /** |
|
41 | + * @var \DateInterval |
|
42 | + */ |
|
43 | 43 | protected $interval; |
44 | 44 | |
45 | - /** |
|
46 | - * @var int |
|
47 | - */ |
|
45 | + /** |
|
46 | + * @var int |
|
47 | + */ |
|
48 | 48 | protected $seconds; |
49 | 49 | |
50 | 50 | protected function __construct(int $seconds) |
@@ -69,33 +69,33 @@ discard block |
||
69 | 69 | $this->interval = $interval; |
70 | 70 | } |
71 | 71 | |
72 | - /** |
|
73 | - * Creates the interval from a specific amount of seconds. |
|
74 | - * |
|
75 | - * @param int $seconds |
|
76 | - * @return \AppUtils\ConvertHelper_DateInterval |
|
77 | - */ |
|
72 | + /** |
|
73 | + * Creates the interval from a specific amount of seconds. |
|
74 | + * |
|
75 | + * @param int $seconds |
|
76 | + * @return \AppUtils\ConvertHelper_DateInterval |
|
77 | + */ |
|
78 | 78 | public static function fromSeconds(int $seconds) |
79 | 79 | { |
80 | 80 | return new ConvertHelper_DateInterval($seconds); |
81 | 81 | } |
82 | 82 | |
83 | - /** |
|
84 | - * Creates the interval from an existing regular interval instance. |
|
85 | - * |
|
86 | - * @param \DateInterval $interval |
|
87 | - * @return \AppUtils\ConvertHelper_DateInterval |
|
88 | - */ |
|
83 | + /** |
|
84 | + * Creates the interval from an existing regular interval instance. |
|
85 | + * |
|
86 | + * @param \DateInterval $interval |
|
87 | + * @return \AppUtils\ConvertHelper_DateInterval |
|
88 | + */ |
|
89 | 89 | public static function fromInterval(\DateInterval $interval) |
90 | 90 | { |
91 | 91 | return self::fromSeconds(ConvertHelper::interval2seconds($interval)); |
92 | 92 | } |
93 | 93 | |
94 | - /** |
|
95 | - * Retrieves the PHP native date interval. |
|
96 | - * |
|
97 | - * @return \DateInterval |
|
98 | - */ |
|
94 | + /** |
|
95 | + * Retrieves the PHP native date interval. |
|
96 | + * |
|
97 | + * @return \DateInterval |
|
98 | + */ |
|
99 | 99 | public function getInterval() : \DateInterval |
100 | 100 | { |
101 | 101 | return $this->interval; |
@@ -131,31 +131,31 @@ discard block |
||
131 | 131 | return $this->getToken(self::TOKEN_YEARS); |
132 | 132 | } |
133 | 133 | |
134 | - /** |
|
135 | - * Retrieves a specific time token, e.g. "h" (for hours). |
|
136 | - * Using the constants to specifiy the tokens is recommended. |
|
137 | - * |
|
138 | - * @param string $token |
|
139 | - * @return int |
|
140 | - * |
|
141 | - * @see ConvertHelper_DateInterval::TOKEN_SECONDS |
|
142 | - * @see ConvertHelper_DateInterval::TOKEN_MINUTES |
|
143 | - * @see ConvertHelper_DateInterval::TOKEN_HOURS |
|
144 | - * @see ConvertHelper_DateInterval::TOKEN_DAYS |
|
145 | - * @see ConvertHelper_DateInterval::TOKEN_MONTHS |
|
146 | - * @see ConvertHelper_DateInterval::TOKEN_YEARS |
|
147 | - */ |
|
134 | + /** |
|
135 | + * Retrieves a specific time token, e.g. "h" (for hours). |
|
136 | + * Using the constants to specifiy the tokens is recommended. |
|
137 | + * |
|
138 | + * @param string $token |
|
139 | + * @return int |
|
140 | + * |
|
141 | + * @see ConvertHelper_DateInterval::TOKEN_SECONDS |
|
142 | + * @see ConvertHelper_DateInterval::TOKEN_MINUTES |
|
143 | + * @see ConvertHelper_DateInterval::TOKEN_HOURS |
|
144 | + * @see ConvertHelper_DateInterval::TOKEN_DAYS |
|
145 | + * @see ConvertHelper_DateInterval::TOKEN_MONTHS |
|
146 | + * @see ConvertHelper_DateInterval::TOKEN_YEARS |
|
147 | + */ |
|
148 | 148 | public function getToken(string $token) : int |
149 | 149 | { |
150 | 150 | return (int)$this->interval->$token; |
151 | 151 | } |
152 | 152 | |
153 | - /** |
|
154 | - * The total amount of seconds in the interval (including |
|
155 | - * everything, from seconds to days, months, years...). |
|
156 | - * |
|
157 | - * @return int |
|
158 | - */ |
|
153 | + /** |
|
154 | + * The total amount of seconds in the interval (including |
|
155 | + * everything, from seconds to days, months, years...). |
|
156 | + * |
|
157 | + * @return int |
|
158 | + */ |
|
159 | 159 | public function getTotalSeconds() : int |
160 | 160 | { |
161 | 161 | return $this->seconds; |
@@ -26,39 +26,39 @@ discard block |
||
26 | 26 | const ERROR_NO_DATE_FROM_SET = 43401; |
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * @var int |
|
31 | - */ |
|
29 | + /** |
|
30 | + * @var int |
|
31 | + */ |
|
32 | 32 | protected $dateFrom; |
33 | 33 | |
34 | - /** |
|
35 | - * @var int |
|
36 | - */ |
|
34 | + /** |
|
35 | + * @var int |
|
36 | + */ |
|
37 | 37 | protected $dateTo; |
38 | 38 | |
39 | - /** |
|
40 | - * @var bool |
|
41 | - */ |
|
39 | + /** |
|
40 | + * @var bool |
|
41 | + */ |
|
42 | 42 | protected $future = false; |
43 | 43 | |
44 | - /** |
|
45 | - * @var string |
|
46 | - */ |
|
44 | + /** |
|
45 | + * @var string |
|
46 | + */ |
|
47 | 47 | protected $interval = ''; |
48 | 48 | |
49 | - /** |
|
50 | - * @var int |
|
51 | - */ |
|
49 | + /** |
|
50 | + * @var int |
|
51 | + */ |
|
52 | 52 | protected $difference = 0; |
53 | 53 | |
54 | - /** |
|
55 | - * @var int |
|
56 | - */ |
|
54 | + /** |
|
55 | + * @var int |
|
56 | + */ |
|
57 | 57 | protected $dateDiff = 0; |
58 | 58 | |
59 | - /** |
|
60 | - * @var array |
|
61 | - */ |
|
59 | + /** |
|
60 | + * @var array |
|
61 | + */ |
|
62 | 62 | protected static $texts; |
63 | 63 | |
64 | 64 | public function __construct() |
@@ -78,17 +78,17 @@ discard block |
||
78 | 78 | unset(self::$texts); |
79 | 79 | } |
80 | 80 | |
81 | - /** |
|
82 | - * Sets the origin date to calculate from. |
|
83 | - * |
|
84 | - * NOTE: if this is further in the future than |
|
85 | - * the to: date, it will be considered as a |
|
86 | - * calculation for something to come, i.e. |
|
87 | - * "In two days". |
|
88 | - * |
|
89 | - * @param \DateTime $date |
|
90 | - * @return ConvertHelper_DurationConverter |
|
91 | - */ |
|
81 | + /** |
|
82 | + * Sets the origin date to calculate from. |
|
83 | + * |
|
84 | + * NOTE: if this is further in the future than |
|
85 | + * the to: date, it will be considered as a |
|
86 | + * calculation for something to come, i.e. |
|
87 | + * "In two days". |
|
88 | + * |
|
89 | + * @param \DateTime $date |
|
90 | + * @return ConvertHelper_DurationConverter |
|
91 | + */ |
|
92 | 92 | public function setDateFrom(\DateTime $date) : ConvertHelper_DurationConverter |
93 | 93 | { |
94 | 94 | $this->dateFrom = ConvertHelper::date2timestamp($date); |
@@ -96,13 +96,13 @@ discard block |
||
96 | 96 | return $this; |
97 | 97 | } |
98 | 98 | |
99 | - /** |
|
100 | - * Sets the date to calculate to. Defaults to |
|
101 | - * the current time if not set. |
|
102 | - * |
|
103 | - * @param \DateTime $date |
|
104 | - * @return ConvertHelper_DurationConverter |
|
105 | - */ |
|
99 | + /** |
|
100 | + * Sets the date to calculate to. Defaults to |
|
101 | + * the current time if not set. |
|
102 | + * |
|
103 | + * @param \DateTime $date |
|
104 | + * @return ConvertHelper_DurationConverter |
|
105 | + */ |
|
106 | 106 | public function setDateTo(\DateTime $date) : ConvertHelper_DurationConverter |
107 | 107 | { |
108 | 108 | $this->dateTo = ConvertHelper::date2timestamp($date); |
@@ -110,14 +110,14 @@ discard block |
||
110 | 110 | return $this; |
111 | 111 | } |
112 | 112 | |
113 | - /** |
|
114 | - * Converts the specified dates to a human readable string. |
|
115 | - * |
|
116 | - * @throws ConvertHelper_Exception |
|
117 | - * @return string |
|
118 | - * |
|
119 | - * @see ConvertHelper_DurationConverter::ERROR_NO_DATE_FROM_SET |
|
120 | - */ |
|
113 | + /** |
|
114 | + * Converts the specified dates to a human readable string. |
|
115 | + * |
|
116 | + * @throws ConvertHelper_Exception |
|
117 | + * @return string |
|
118 | + * |
|
119 | + * @see ConvertHelper_DurationConverter::ERROR_NO_DATE_FROM_SET |
|
120 | + */ |
|
121 | 121 | public function convert() : string |
122 | 122 | { |
123 | 123 | $this->initTexts(); |
@@ -17,21 +17,20 @@ discard block |
||
17 | 17 | * @package Application Utils |
18 | 18 | * @subpackage ConvertHelper |
19 | 19 | * @author Sebastian Mordziol <[email protected]> |
20 | - |
|
21 | 20 | * @see ConvertHelper::interval2string() |
22 | 21 | */ |
23 | 22 | class ConvertHelper_IntervalConverter |
24 | 23 | { |
25 | 24 | const ERROR_MISSING_TRANSLATION = 43501; |
26 | 25 | |
27 | - /** |
|
28 | - * @var array |
|
29 | - */ |
|
26 | + /** |
|
27 | + * @var array |
|
28 | + */ |
|
30 | 29 | protected static $texts; |
31 | 30 | |
32 | - /** |
|
33 | - * @var array |
|
34 | - */ |
|
31 | + /** |
|
32 | + * @var array |
|
33 | + */ |
|
35 | 34 | protected $tokens = array('y', 'm', 'd', 'h', 'i', 's'); |
36 | 35 | |
37 | 36 | public function __construct() |
@@ -41,25 +40,25 @@ discard block |
||
41 | 40 | } |
42 | 41 | } |
43 | 42 | |
44 | - /** |
|
45 | - * Called whenever the application locale has changed, |
|
46 | - * to reset the internal translation cache. |
|
47 | - */ |
|
43 | + /** |
|
44 | + * Called whenever the application locale has changed, |
|
45 | + * to reset the internal translation cache. |
|
46 | + */ |
|
48 | 47 | public function handle_localeChanged() |
49 | 48 | { |
50 | 49 | unset(self::$texts); |
51 | 50 | } |
52 | 51 | |
53 | - /** |
|
54 | - * Converts the specified interval to a human readable |
|
55 | - * string, e.g. "2 hours and 4 minutes". |
|
56 | - * |
|
57 | - * @param \DateInterval $interval |
|
58 | - * @return string |
|
59 | - * @throws ConvertHelper_Exception |
|
60 | - * |
|
61 | - * @see ConvertHelper_IntervalConverter::ERROR_MISSING_TRANSLATION |
|
62 | - */ |
|
52 | + /** |
|
53 | + * Converts the specified interval to a human readable |
|
54 | + * string, e.g. "2 hours and 4 minutes". |
|
55 | + * |
|
56 | + * @param \DateInterval $interval |
|
57 | + * @return string |
|
58 | + * @throws ConvertHelper_Exception |
|
59 | + * |
|
60 | + * @see ConvertHelper_IntervalConverter::ERROR_MISSING_TRANSLATION |
|
61 | + */ |
|
63 | 62 | public function toString(\DateInterval $interval) : string |
64 | 63 | { |
65 | 64 | $this->initTexts(); |
@@ -88,14 +87,14 @@ discard block |
||
88 | 87 | return t('%1$s and %2$s', implode(', ', $parts), $last); |
89 | 88 | } |
90 | 89 | |
91 | - /** |
|
92 | - * Translates the selected time token, e.g. "y" (for year). |
|
93 | - * |
|
94 | - * @param string $token |
|
95 | - * @param ConvertHelper_DateInterval $interval |
|
96 | - * @throws ConvertHelper_Exception |
|
97 | - * @return string |
|
98 | - */ |
|
90 | + /** |
|
91 | + * Translates the selected time token, e.g. "y" (for year). |
|
92 | + * |
|
93 | + * @param string $token |
|
94 | + * @param ConvertHelper_DateInterval $interval |
|
95 | + * @throws ConvertHelper_Exception |
|
96 | + * @return string |
|
97 | + */ |
|
99 | 98 | protected function translateToken(string $token, ConvertHelper_DateInterval $interval) : string |
100 | 99 | { |
101 | 100 | $value = $interval->getToken($token); |
@@ -123,13 +122,13 @@ discard block |
||
123 | 122 | ); |
124 | 123 | } |
125 | 124 | |
126 | - /** |
|
127 | - * Resolves all time tokens that need to be translated in |
|
128 | - * the subject interval, depending on its length. |
|
129 | - * |
|
130 | - * @param ConvertHelper_DateInterval $interval |
|
131 | - * @return array |
|
132 | - */ |
|
125 | + /** |
|
126 | + * Resolves all time tokens that need to be translated in |
|
127 | + * the subject interval, depending on its length. |
|
128 | + * |
|
129 | + * @param ConvertHelper_DateInterval $interval |
|
130 | + * @return array |
|
131 | + */ |
|
133 | 132 | protected function resolveTokens(ConvertHelper_DateInterval $interval) : array |
134 | 133 | { |
135 | 134 | $offset = 0; |
@@ -147,9 +146,9 @@ discard block |
||
147 | 146 | return array(); |
148 | 147 | } |
149 | 148 | |
150 | - /** |
|
151 | - * Initializes the translateable strings. |
|
152 | - */ |
|
149 | + /** |
|
150 | + * Initializes the translateable strings. |
|
151 | + */ |
|
153 | 152 | protected function initTexts() : void |
154 | 153 | { |
155 | 154 | if(isset(self::$texts)) { |
@@ -160,41 +160,41 @@ discard block |
||
160 | 160 | return implode(', ', $tokens) . ' ' . t('and') . ' ' . $last; |
161 | 161 | } |
162 | 162 | |
163 | - /** |
|
164 | - * Converts a timestamp into an easily understandable |
|
165 | - * format, e.g. "2 hours", "1 day", "3 months" |
|
166 | - * |
|
167 | - * If you set the date to parameter, the difference |
|
168 | - * will be calculated between the two dates and not |
|
169 | - * the current time. |
|
170 | - * |
|
171 | - * @param integer|\DateTime $datefrom |
|
172 | - * @param integer|\DateTime $dateto |
|
173 | - * @return string |
|
174 | - */ |
|
163 | + /** |
|
164 | + * Converts a timestamp into an easily understandable |
|
165 | + * format, e.g. "2 hours", "1 day", "3 months" |
|
166 | + * |
|
167 | + * If you set the date to parameter, the difference |
|
168 | + * will be calculated between the two dates and not |
|
169 | + * the current time. |
|
170 | + * |
|
171 | + * @param integer|\DateTime $datefrom |
|
172 | + * @param integer|\DateTime $dateto |
|
173 | + * @return string |
|
174 | + */ |
|
175 | 175 | public static function duration2string($datefrom, $dateto = -1) : string |
176 | 176 | { |
177 | - $converter = new ConvertHelper_DurationConverter(); |
|
177 | + $converter = new ConvertHelper_DurationConverter(); |
|
178 | 178 | |
179 | - if($datefrom instanceof \DateTime) |
|
180 | - { |
|
181 | - $converter->setDateFrom($datefrom); |
|
182 | - } |
|
183 | - else |
|
184 | - { |
|
185 | - $converter->setDateFrom(self::timestamp2date($datefrom)); |
|
186 | - } |
|
179 | + if($datefrom instanceof \DateTime) |
|
180 | + { |
|
181 | + $converter->setDateFrom($datefrom); |
|
182 | + } |
|
183 | + else |
|
184 | + { |
|
185 | + $converter->setDateFrom(self::timestamp2date($datefrom)); |
|
186 | + } |
|
187 | 187 | |
188 | - if($dateto instanceof \DateTime) |
|
189 | - { |
|
190 | - $converter->setDateTo($dateto); |
|
191 | - } |
|
192 | - else if($dateto > 0) |
|
193 | - { |
|
194 | - $converter->setDateTo(self::timestamp2date($dateto)); |
|
195 | - } |
|
188 | + if($dateto instanceof \DateTime) |
|
189 | + { |
|
190 | + $converter->setDateTo($dateto); |
|
191 | + } |
|
192 | + else if($dateto > 0) |
|
193 | + { |
|
194 | + $converter->setDateTo(self::timestamp2date($dateto)); |
|
195 | + } |
|
196 | 196 | |
197 | - return $converter->convert(); |
|
197 | + return $converter->convert(); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | /** |
@@ -267,16 +267,16 @@ discard block |
||
267 | 267 | return $bytes . ' ' . t('B'); |
268 | 268 | } |
269 | 269 | |
270 | - /** |
|
271 | - * Cuts a text to the specified length if it is longer than the |
|
272 | - * target length. Appends a text to signify it has been cut at |
|
273 | - * the end of the string. |
|
274 | - * |
|
275 | - * @param string $text |
|
276 | - * @param int $targetLength |
|
277 | - * @param string $append |
|
278 | - * @return string |
|
279 | - */ |
|
270 | + /** |
|
271 | + * Cuts a text to the specified length if it is longer than the |
|
272 | + * target length. Appends a text to signify it has been cut at |
|
273 | + * the end of the string. |
|
274 | + * |
|
275 | + * @param string $text |
|
276 | + * @param int $targetLength |
|
277 | + * @param string $append |
|
278 | + * @return string |
|
279 | + */ |
|
280 | 280 | public static function text_cut(string $text, int $targetLength, string $append = '...') : string |
281 | 281 | { |
282 | 282 | $length = mb_strlen($text); |
@@ -346,27 +346,27 @@ discard block |
||
346 | 346 | return self::$booleanStrings[$string]; |
347 | 347 | } |
348 | 348 | |
349 | - /** |
|
350 | - * Whether the specified string is a boolean string or boolean value. |
|
351 | - * Alias for {@link ConvertHelper::isBoolean()}. |
|
352 | - * |
|
353 | - * @param mixed $string |
|
354 | - * @return bool |
|
355 | - * @deprecated |
|
356 | - * @see ConvertHelper::isBoolean() |
|
357 | - */ |
|
349 | + /** |
|
350 | + * Whether the specified string is a boolean string or boolean value. |
|
351 | + * Alias for {@link ConvertHelper::isBoolean()}. |
|
352 | + * |
|
353 | + * @param mixed $string |
|
354 | + * @return bool |
|
355 | + * @deprecated |
|
356 | + * @see ConvertHelper::isBoolean() |
|
357 | + */ |
|
358 | 358 | public static function isBooleanString($string) : bool |
359 | 359 | { |
360 | 360 | return self::isBoolean($string); |
361 | 361 | } |
362 | 362 | |
363 | - /** |
|
364 | - * Alias for the {@\AppUtils\XMLHelper::string2xml()} method. |
|
365 | - * |
|
366 | - * @param string $text |
|
367 | - * @return string |
|
368 | - * @deprecated |
|
369 | - */ |
|
363 | + /** |
|
364 | + * Alias for the {@\AppUtils\XMLHelper::string2xml()} method. |
|
365 | + * |
|
366 | + * @param string $text |
|
367 | + * @return string |
|
368 | + * @deprecated |
|
369 | + */ |
|
370 | 370 | public static function text_makeXMLCompliant($text) |
371 | 371 | { |
372 | 372 | return XMLHelper::string2xml($text); |
@@ -468,13 +468,13 @@ discard block |
||
468 | 468 | return $translit->convert($string); |
469 | 469 | } |
470 | 470 | |
471 | - /** |
|
472 | - * Retrieves the HEX character codes for all control |
|
473 | - * characters that the {@link stripControlCharacters()} |
|
474 | - * method will remove. |
|
475 | - * |
|
476 | - * @return string[] |
|
477 | - */ |
|
471 | + /** |
|
472 | + * Retrieves the HEX character codes for all control |
|
473 | + * characters that the {@link stripControlCharacters()} |
|
474 | + * method will remove. |
|
475 | + * |
|
476 | + * @return string[] |
|
477 | + */ |
|
478 | 478 | public static function getControlCharactersAsHex() |
479 | 479 | { |
480 | 480 | $hexAlphabet = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); |
@@ -510,13 +510,13 @@ discard block |
||
510 | 510 | return $stack; |
511 | 511 | } |
512 | 512 | |
513 | - /** |
|
514 | - * Retrieves an array of all control characters that |
|
515 | - * the {@link stripControlCharacters()} method will |
|
516 | - * remove, as the actual UTF-8 characters. |
|
517 | - * |
|
518 | - * @return string[] |
|
519 | - */ |
|
513 | + /** |
|
514 | + * Retrieves an array of all control characters that |
|
515 | + * the {@link stripControlCharacters()} method will |
|
516 | + * remove, as the actual UTF-8 characters. |
|
517 | + * |
|
518 | + * @return string[] |
|
519 | + */ |
|
520 | 520 | public static function getControlCharactersAsUTF8() |
521 | 521 | { |
522 | 522 | $chars = self::getControlCharactersAsHex(); |
@@ -529,12 +529,12 @@ discard block |
||
529 | 529 | return $result; |
530 | 530 | } |
531 | 531 | |
532 | - /** |
|
533 | - * Retrieves all control characters as JSON encoded |
|
534 | - * characters, e.g. "\u200b". |
|
535 | - * |
|
536 | - * @return string[] |
|
537 | - */ |
|
532 | + /** |
|
533 | + * Retrieves all control characters as JSON encoded |
|
534 | + * characters, e.g. "\u200b". |
|
535 | + * |
|
536 | + * @return string[] |
|
537 | + */ |
|
538 | 538 | public static function getControlCharactersAsJSON() |
539 | 539 | { |
540 | 540 | $chars = self::getControlCharactersAsHex(); |
@@ -591,20 +591,20 @@ discard block |
||
591 | 591 | return preg_replace(self::$controlCharsRegex, '', $string); |
592 | 592 | } |
593 | 593 | |
594 | - /** |
|
595 | - * Converts a unicode character to the PHPO notation. |
|
596 | - * |
|
597 | - * Example: |
|
598 | - * |
|
599 | - * <pre>unicodeChar2php('"\u0000"')</pre> |
|
600 | - * |
|
601 | - * Returns |
|
602 | - * |
|
603 | - * <pre>\x0</pre> |
|
604 | - * |
|
605 | - * @param string $unicodeChar |
|
606 | - * @return string |
|
607 | - */ |
|
594 | + /** |
|
595 | + * Converts a unicode character to the PHPO notation. |
|
596 | + * |
|
597 | + * Example: |
|
598 | + * |
|
599 | + * <pre>unicodeChar2php('"\u0000"')</pre> |
|
600 | + * |
|
601 | + * Returns |
|
602 | + * |
|
603 | + * <pre>\x0</pre> |
|
604 | + * |
|
605 | + * @param string $unicodeChar |
|
606 | + * @return string |
|
607 | + */ |
|
608 | 608 | public static function unicodeChar2php($unicodeChar) |
609 | 609 | { |
610 | 610 | $unicodeChar = json_decode($unicodeChar); |
@@ -727,25 +727,25 @@ discard block |
||
727 | 727 | return 'false'; |
728 | 728 | } |
729 | 729 | |
730 | - /** |
|
731 | - * Converts an associative array with attribute name > value pairs |
|
732 | - * to an attribute string that can be used in an HTML tag. Empty |
|
733 | - * attribute values are ignored. |
|
734 | - * |
|
735 | - * Example: |
|
736 | - * |
|
737 | - * array2attributeString(array( |
|
738 | - * 'id' => 45, |
|
739 | - * 'href' => 'http://www.mistralys.com' |
|
740 | - * )); |
|
741 | - * |
|
742 | - * Result: |
|
743 | - * |
|
744 | - * id="45" href="http://www.mistralys.com" |
|
745 | - * |
|
746 | - * @param array $array |
|
747 | - * @return string |
|
748 | - */ |
|
730 | + /** |
|
731 | + * Converts an associative array with attribute name > value pairs |
|
732 | + * to an attribute string that can be used in an HTML tag. Empty |
|
733 | + * attribute values are ignored. |
|
734 | + * |
|
735 | + * Example: |
|
736 | + * |
|
737 | + * array2attributeString(array( |
|
738 | + * 'id' => 45, |
|
739 | + * 'href' => 'http://www.mistralys.com' |
|
740 | + * )); |
|
741 | + * |
|
742 | + * Result: |
|
743 | + * |
|
744 | + * id="45" href="http://www.mistralys.com" |
|
745 | + * |
|
746 | + * @param array $array |
|
747 | + * @return string |
|
748 | + */ |
|
749 | 749 | public static function array2attributeString($array) |
750 | 750 | { |
751 | 751 | $tokens = array(); |
@@ -764,14 +764,14 @@ discard block |
||
764 | 764 | return ' '.implode(' ', $tokens); |
765 | 765 | } |
766 | 766 | |
767 | - /** |
|
768 | - * Converts a string so it can safely be used in a javascript |
|
769 | - * statement in an HTML tag: uses single quotes around the string |
|
770 | - * and encodes all special characters as needed. |
|
771 | - * |
|
772 | - * @param string $string |
|
773 | - * @return string |
|
774 | - */ |
|
767 | + /** |
|
768 | + * Converts a string so it can safely be used in a javascript |
|
769 | + * statement in an HTML tag: uses single quotes around the string |
|
770 | + * and encodes all special characters as needed. |
|
771 | + * |
|
772 | + * @param string $string |
|
773 | + * @return string |
|
774 | + */ |
|
775 | 775 | public static function string2attributeJS($string, $quoted=true) |
776 | 776 | { |
777 | 777 | $converted = addslashes(htmlspecialchars(strip_tags($string), ENT_QUOTES, 'UTF-8')); |
@@ -782,15 +782,15 @@ discard block |
||
782 | 782 | return $converted; |
783 | 783 | } |
784 | 784 | |
785 | - /** |
|
786 | - * Checks if the specified string is a boolean value, which |
|
787 | - * includes string representations of boolean values, like |
|
788 | - * <code>yes</code> or <code>no</code>, and <code>true</code> |
|
789 | - * or <code>false</code>. |
|
790 | - * |
|
791 | - * @param mixed $value |
|
792 | - * @return boolean |
|
793 | - */ |
|
785 | + /** |
|
786 | + * Checks if the specified string is a boolean value, which |
|
787 | + * includes string representations of boolean values, like |
|
788 | + * <code>yes</code> or <code>no</code>, and <code>true</code> |
|
789 | + * or <code>false</code>. |
|
790 | + * |
|
791 | + * @param mixed $value |
|
792 | + * @return boolean |
|
793 | + */ |
|
794 | 794 | public static function isBoolean($value) : bool |
795 | 795 | { |
796 | 796 | if(is_bool($value)) { |
@@ -804,12 +804,12 @@ discard block |
||
804 | 804 | return array_key_exists($value, self::$booleanStrings); |
805 | 805 | } |
806 | 806 | |
807 | - /** |
|
808 | - * Converts an associative array to an HTML style attribute value string. |
|
809 | - * |
|
810 | - * @param array $subject |
|
811 | - * @return string |
|
812 | - */ |
|
807 | + /** |
|
808 | + * Converts an associative array to an HTML style attribute value string. |
|
809 | + * |
|
810 | + * @param array $subject |
|
811 | + * @return string |
|
812 | + */ |
|
813 | 813 | public static function array2styleString(array $subject) : string |
814 | 814 | { |
815 | 815 | $tokens = array(); |
@@ -820,23 +820,23 @@ discard block |
||
820 | 820 | return implode(';', $tokens); |
821 | 821 | } |
822 | 822 | |
823 | - /** |
|
824 | - * Converts a DateTime object to a timestamp, which |
|
825 | - * is PHP 5.2 compatible. |
|
826 | - * |
|
827 | - * @param \DateTime $date |
|
828 | - * @return integer |
|
829 | - */ |
|
823 | + /** |
|
824 | + * Converts a DateTime object to a timestamp, which |
|
825 | + * is PHP 5.2 compatible. |
|
826 | + * |
|
827 | + * @param \DateTime $date |
|
828 | + * @return integer |
|
829 | + */ |
|
830 | 830 | public static function date2timestamp(\DateTime $date) : int |
831 | 831 | { |
832 | 832 | return (int)$date->format('U'); |
833 | 833 | } |
834 | 834 | |
835 | - /** |
|
836 | - * Converts a timestamp into a DateTime instance. |
|
837 | - * @param int $timestamp |
|
838 | - * @return \DateTime |
|
839 | - */ |
|
835 | + /** |
|
836 | + * Converts a timestamp into a DateTime instance. |
|
837 | + * @param int $timestamp |
|
838 | + * @return \DateTime |
|
839 | + */ |
|
840 | 840 | public static function timestamp2date(int $timestamp) : \DateTime |
841 | 841 | { |
842 | 842 | $date = new \DateTime(); |
@@ -844,50 +844,50 @@ discard block |
||
844 | 844 | return $date; |
845 | 845 | } |
846 | 846 | |
847 | - /** |
|
848 | - * Strips an absolute path to a file within the application |
|
849 | - * to make the path relative to the application root path. |
|
850 | - * |
|
851 | - * @param string $path |
|
852 | - * @return string |
|
853 | - * |
|
854 | - * @see FileHelper::relativizePath() |
|
855 | - * @see FileHelper::relativizePathByDepth() |
|
856 | - */ |
|
847 | + /** |
|
848 | + * Strips an absolute path to a file within the application |
|
849 | + * to make the path relative to the application root path. |
|
850 | + * |
|
851 | + * @param string $path |
|
852 | + * @return string |
|
853 | + * |
|
854 | + * @see FileHelper::relativizePath() |
|
855 | + * @see FileHelper::relativizePathByDepth() |
|
856 | + */ |
|
857 | 857 | public static function fileRelativize(string $path) : string |
858 | 858 | { |
859 | 859 | return FileHelper::relativizePathByDepth($path); |
860 | 860 | } |
861 | 861 | |
862 | 862 | /** |
863 | - * Converts a PHP regex to a javascript RegExp object statement. |
|
864 | - * |
|
865 | - * NOTE: This is an alias for the JSHelper's `convertRegex` method. |
|
866 | - * More details are available on its usage there. |
|
867 | - * |
|
868 | - * @param string $regex A PHP preg regex |
|
869 | - * @param string $statementType The type of statement to return: Defaults to a statement to create a RegExp object. |
|
870 | - * @return array|string Depending on the specified return type. |
|
871 | - * |
|
872 | - * @see JSHelper::buildRegexStatement() |
|
873 | - */ |
|
863 | + * Converts a PHP regex to a javascript RegExp object statement. |
|
864 | + * |
|
865 | + * NOTE: This is an alias for the JSHelper's `convertRegex` method. |
|
866 | + * More details are available on its usage there. |
|
867 | + * |
|
868 | + * @param string $regex A PHP preg regex |
|
869 | + * @param string $statementType The type of statement to return: Defaults to a statement to create a RegExp object. |
|
870 | + * @return array|string Depending on the specified return type. |
|
871 | + * |
|
872 | + * @see JSHelper::buildRegexStatement() |
|
873 | + */ |
|
874 | 874 | public static function regex2js(string $regex, string $statementType=JSHelper::JS_REGEX_OBJECT) |
875 | 875 | { |
876 | 876 | return JSHelper::buildRegexStatement($regex, $statementType); |
877 | 877 | } |
878 | 878 | |
879 | - /** |
|
880 | - * Converts the specified variable to JSON. Works just |
|
881 | - * like the native `json_encode` method, except that it |
|
882 | - * will trigger an exception on failure, which has the |
|
883 | - * json error details included in its developer details. |
|
884 | - * |
|
885 | - * @param mixed $variable |
|
886 | - * @param int|NULL $options JSON encode options. |
|
887 | - * @param int|NULL $depth |
|
888 | - * @throws ConvertHelper_Exception |
|
889 | - * @return string |
|
890 | - */ |
|
879 | + /** |
|
880 | + * Converts the specified variable to JSON. Works just |
|
881 | + * like the native `json_encode` method, except that it |
|
882 | + * will trigger an exception on failure, which has the |
|
883 | + * json error details included in its developer details. |
|
884 | + * |
|
885 | + * @param mixed $variable |
|
886 | + * @param int|NULL $options JSON encode options. |
|
887 | + * @param int|NULL $depth |
|
888 | + * @throws ConvertHelper_Exception |
|
889 | + * @return string |
|
890 | + */ |
|
891 | 891 | public static function var2json($variable, int $options=0, int $depth=512) : string |
892 | 892 | { |
893 | 893 | $result = json_encode($variable, $options, $depth); |
@@ -908,12 +908,12 @@ discard block |
||
908 | 908 | ); |
909 | 909 | } |
910 | 910 | |
911 | - /** |
|
912 | - * Strips all known UTF byte order marks from the specified string. |
|
913 | - * |
|
914 | - * @param string $string |
|
915 | - * @return string |
|
916 | - */ |
|
911 | + /** |
|
912 | + * Strips all known UTF byte order marks from the specified string. |
|
913 | + * |
|
914 | + * @param string $string |
|
915 | + * @return string |
|
916 | + */ |
|
917 | 917 | public static function stripUTFBom($string) |
918 | 918 | { |
919 | 919 | $boms = FileHelper::getUTFBOMs(); |
@@ -928,13 +928,13 @@ discard block |
||
928 | 928 | return $string; |
929 | 929 | } |
930 | 930 | |
931 | - /** |
|
932 | - * Converts a string to valid utf8, regardless |
|
933 | - * of the string's encoding(s). |
|
934 | - * |
|
935 | - * @param string $string |
|
936 | - * @return string |
|
937 | - */ |
|
931 | + /** |
|
932 | + * Converts a string to valid utf8, regardless |
|
933 | + * of the string's encoding(s). |
|
934 | + * |
|
935 | + * @param string $string |
|
936 | + * @return string |
|
937 | + */ |
|
938 | 938 | public static function string2utf8($string) |
939 | 939 | { |
940 | 940 | if(!self::isStringASCII($string)) { |
@@ -944,15 +944,15 @@ discard block |
||
944 | 944 | return $string; |
945 | 945 | } |
946 | 946 | |
947 | - /** |
|
948 | - * Checks whether the specified string is an ASCII |
|
949 | - * string, without any special or UTF8 characters. |
|
950 | - * Note: empty strings and NULL are considered ASCII. |
|
951 | - * Any variable types other than strings are not. |
|
952 | - * |
|
953 | - * @param mixed $string |
|
954 | - * @return boolean |
|
955 | - */ |
|
947 | + /** |
|
948 | + * Checks whether the specified string is an ASCII |
|
949 | + * string, without any special or UTF8 characters. |
|
950 | + * Note: empty strings and NULL are considered ASCII. |
|
951 | + * Any variable types other than strings are not. |
|
952 | + * |
|
953 | + * @param mixed $string |
|
954 | + * @return boolean |
|
955 | + */ |
|
956 | 956 | public static function isStringASCII($string) : bool |
957 | 957 | { |
958 | 958 | if($string === '' || $string === NULL) { |
@@ -977,22 +977,22 @@ discard block |
||
977 | 977 | return $url; |
978 | 978 | } |
979 | 979 | |
980 | - /** |
|
981 | - * Calculates a percentage match of the source string with the target string. |
|
982 | - * |
|
983 | - * Options are: |
|
984 | - * |
|
985 | - * - maxLevenshtein, default: 10 |
|
986 | - * Any levenshtein results above this value are ignored. |
|
987 | - * |
|
988 | - * - precision, default: 1 |
|
989 | - * The precision of the percentage float value |
|
990 | - * |
|
991 | - * @param string $source |
|
992 | - * @param string $target |
|
993 | - * @param array $options |
|
994 | - * @return float |
|
995 | - */ |
|
980 | + /** |
|
981 | + * Calculates a percentage match of the source string with the target string. |
|
982 | + * |
|
983 | + * Options are: |
|
984 | + * |
|
985 | + * - maxLevenshtein, default: 10 |
|
986 | + * Any levenshtein results above this value are ignored. |
|
987 | + * |
|
988 | + * - precision, default: 1 |
|
989 | + * The precision of the percentage float value |
|
990 | + * |
|
991 | + * @param string $source |
|
992 | + * @param string $target |
|
993 | + * @param array $options |
|
994 | + * @return float |
|
995 | + */ |
|
996 | 996 | public static function matchString($source, $target, $options=array()) |
997 | 997 | { |
998 | 998 | $defaults = array( |
@@ -1016,14 +1016,14 @@ discard block |
||
1016 | 1016 | return round(100 - $percent, $options['precision']); |
1017 | 1017 | } |
1018 | 1018 | |
1019 | - /** |
|
1020 | - * Converts a date interval to a human readable string with |
|
1021 | - * all necessary time components, e.g. "1 year, 2 months and 4 days". |
|
1022 | - * |
|
1023 | - * @param \DateInterval $interval |
|
1024 | - * @return string |
|
1025 | - * @see ConvertHelper_IntervalConverter |
|
1026 | - */ |
|
1019 | + /** |
|
1020 | + * Converts a date interval to a human readable string with |
|
1021 | + * all necessary time components, e.g. "1 year, 2 months and 4 days". |
|
1022 | + * |
|
1023 | + * @param \DateInterval $interval |
|
1024 | + * @return string |
|
1025 | + * @see ConvertHelper_IntervalConverter |
|
1026 | + */ |
|
1027 | 1027 | public static function interval2string(\DateInterval $interval) : string |
1028 | 1028 | { |
1029 | 1029 | $converter = new ConvertHelper_IntervalConverter(); |
@@ -1038,60 +1038,60 @@ discard block |
||
1038 | 1038 | |
1039 | 1039 | const INTERVAL_SECONDS = 'seconds'; |
1040 | 1040 | |
1041 | - /** |
|
1042 | - * Converts an interval to its total amount of days. |
|
1043 | - * @param \DateInterval $interval |
|
1044 | - * @return int |
|
1045 | - */ |
|
1041 | + /** |
|
1042 | + * Converts an interval to its total amount of days. |
|
1043 | + * @param \DateInterval $interval |
|
1044 | + * @return int |
|
1045 | + */ |
|
1046 | 1046 | public static function interval2days(\DateInterval $interval) : int |
1047 | 1047 | { |
1048 | 1048 | return self::interval2total($interval, self::INTERVAL_DAYS); |
1049 | 1049 | } |
1050 | 1050 | |
1051 | - /** |
|
1052 | - * Converts an interval to its total amount of hours. |
|
1053 | - * @param \DateInterval $interval |
|
1054 | - * @return int |
|
1055 | - */ |
|
1051 | + /** |
|
1052 | + * Converts an interval to its total amount of hours. |
|
1053 | + * @param \DateInterval $interval |
|
1054 | + * @return int |
|
1055 | + */ |
|
1056 | 1056 | public static function interval2hours(\DateInterval $interval) : int |
1057 | 1057 | { |
1058 | 1058 | return self::interval2total($interval, self::INTERVAL_HOURS); |
1059 | 1059 | } |
1060 | 1060 | |
1061 | - /** |
|
1062 | - * Converts an interval to its total amount of minutes. |
|
1063 | - * @param \DateInterval $interval |
|
1064 | - * @return int |
|
1065 | - */ |
|
1061 | + /** |
|
1062 | + * Converts an interval to its total amount of minutes. |
|
1063 | + * @param \DateInterval $interval |
|
1064 | + * @return int |
|
1065 | + */ |
|
1066 | 1066 | public static function interval2minutes(\DateInterval $interval) : int |
1067 | 1067 | { |
1068 | 1068 | return self::interval2total($interval, self::INTERVAL_MINUTES); |
1069 | 1069 | } |
1070 | 1070 | |
1071 | - /** |
|
1072 | - * Converts an interval to its total amount of seconds. |
|
1073 | - * @param \DateInterval $interval |
|
1074 | - * @return int |
|
1075 | - */ |
|
1071 | + /** |
|
1072 | + * Converts an interval to its total amount of seconds. |
|
1073 | + * @param \DateInterval $interval |
|
1074 | + * @return int |
|
1075 | + */ |
|
1076 | 1076 | public static function interval2seconds(\DateInterval $interval) : int |
1077 | 1077 | { |
1078 | 1078 | return self::interval2total($interval, self::INTERVAL_SECONDS); |
1079 | 1079 | } |
1080 | 1080 | |
1081 | - /** |
|
1082 | - * Calculates the total amount of days / hours / minutes or seconds |
|
1083 | - * of a date interval object (depending in the specified units), and |
|
1084 | - * returns the total amount. |
|
1085 | - * |
|
1086 | - * @param \DateInterval $interval |
|
1087 | - * @param string $unit What total value to calculate. |
|
1088 | - * @return integer |
|
1089 | - * |
|
1090 | - * @see ConvertHelper::INTERVAL_SECONDS |
|
1091 | - * @see ConvertHelper::INTERVAL_MINUTES |
|
1092 | - * @see ConvertHelper::INTERVAL_HOURS |
|
1093 | - * @see ConvertHelper::INTERVAL_DAYS |
|
1094 | - */ |
|
1081 | + /** |
|
1082 | + * Calculates the total amount of days / hours / minutes or seconds |
|
1083 | + * of a date interval object (depending in the specified units), and |
|
1084 | + * returns the total amount. |
|
1085 | + * |
|
1086 | + * @param \DateInterval $interval |
|
1087 | + * @param string $unit What total value to calculate. |
|
1088 | + * @return integer |
|
1089 | + * |
|
1090 | + * @see ConvertHelper::INTERVAL_SECONDS |
|
1091 | + * @see ConvertHelper::INTERVAL_MINUTES |
|
1092 | + * @see ConvertHelper::INTERVAL_HOURS |
|
1093 | + * @see ConvertHelper::INTERVAL_DAYS |
|
1094 | + */ |
|
1095 | 1095 | public static function interval2total(\DateInterval $interval, $unit=self::INTERVAL_SECONDS) : int |
1096 | 1096 | { |
1097 | 1097 | $total = (int)$interval->format('%a'); |
@@ -1131,13 +1131,13 @@ discard block |
||
1131 | 1131 | 'Sunday' |
1132 | 1132 | ); |
1133 | 1133 | |
1134 | - /** |
|
1135 | - * Converts a date to the corresponding day name. |
|
1136 | - * |
|
1137 | - * @param \DateTime $date |
|
1138 | - * @param bool $short |
|
1139 | - * @return string|NULL |
|
1140 | - */ |
|
1134 | + /** |
|
1135 | + * Converts a date to the corresponding day name. |
|
1136 | + * |
|
1137 | + * @param \DateTime $date |
|
1138 | + * @param bool $short |
|
1139 | + * @return string|NULL |
|
1140 | + */ |
|
1141 | 1141 | public static function date2dayName(\DateTime $date, bool $short=false) |
1142 | 1142 | { |
1143 | 1143 | $day = $date->format('l'); |
@@ -1152,21 +1152,21 @@ discard block |
||
1152 | 1152 | return null; |
1153 | 1153 | } |
1154 | 1154 | |
1155 | - /** |
|
1156 | - * Retrieves a list of english day names. |
|
1157 | - * @return string[] |
|
1158 | - */ |
|
1155 | + /** |
|
1156 | + * Retrieves a list of english day names. |
|
1157 | + * @return string[] |
|
1158 | + */ |
|
1159 | 1159 | public static function getDayNamesInvariant() |
1160 | 1160 | { |
1161 | 1161 | return self::$daysInvariant; |
1162 | 1162 | } |
1163 | 1163 | |
1164 | - /** |
|
1165 | - * Retrieves the day names list for the current locale. |
|
1166 | - * |
|
1167 | - * @param bool $short |
|
1168 | - * @return array |
|
1169 | - */ |
|
1164 | + /** |
|
1165 | + * Retrieves the day names list for the current locale. |
|
1166 | + * |
|
1167 | + * @param bool $short |
|
1168 | + * @return array |
|
1169 | + */ |
|
1170 | 1170 | public static function getDayNames(bool $short=false) : array |
1171 | 1171 | { |
1172 | 1172 | if($short) { |
@@ -1226,16 +1226,16 @@ discard block |
||
1226 | 1226 | return $last; |
1227 | 1227 | } |
1228 | 1228 | |
1229 | - /** |
|
1230 | - * Splits a string into an array of all characters it is composed of. |
|
1231 | - * Unicode character safe. |
|
1232 | - * |
|
1233 | - * NOTE: Spaces and newlines (both \r and \n) are also considered single |
|
1234 | - * characters. |
|
1235 | - * |
|
1236 | - * @param string $string |
|
1237 | - * @return array |
|
1238 | - */ |
|
1229 | + /** |
|
1230 | + * Splits a string into an array of all characters it is composed of. |
|
1231 | + * Unicode character safe. |
|
1232 | + * |
|
1233 | + * NOTE: Spaces and newlines (both \r and \n) are also considered single |
|
1234 | + * characters. |
|
1235 | + * |
|
1236 | + * @param string $string |
|
1237 | + * @return array |
|
1238 | + */ |
|
1239 | 1239 | public static function string2array(string $string) : array |
1240 | 1240 | { |
1241 | 1241 | $result = preg_split('//u', $string, null, PREG_SPLIT_NO_EMPTY); |
@@ -1246,12 +1246,12 @@ discard block |
||
1246 | 1246 | return array(); |
1247 | 1247 | } |
1248 | 1248 | |
1249 | - /** |
|
1250 | - * Checks whether the specified string contains HTML code. |
|
1251 | - * |
|
1252 | - * @param string $string |
|
1253 | - * @return boolean |
|
1254 | - */ |
|
1249 | + /** |
|
1250 | + * Checks whether the specified string contains HTML code. |
|
1251 | + * |
|
1252 | + * @param string $string |
|
1253 | + * @return boolean |
|
1254 | + */ |
|
1255 | 1255 | public static function isStringHTML(string $string) : bool |
1256 | 1256 | { |
1257 | 1257 | if(preg_match('%<[a-z/][\s\S]*>%siU', $string)) { |
@@ -1266,17 +1266,17 @@ discard block |
||
1266 | 1266 | return false; |
1267 | 1267 | } |
1268 | 1268 | |
1269 | - /** |
|
1270 | - * UTF8-safe wordwrap method: works like the regular wordwrap |
|
1271 | - * PHP function but compatible with UTF8. Otherwise the lengths |
|
1272 | - * are not calculated correctly. |
|
1273 | - * |
|
1274 | - * @param string $str |
|
1275 | - * @param int $width |
|
1276 | - * @param string $break |
|
1277 | - * @param bool $cut |
|
1278 | - * @return string |
|
1279 | - */ |
|
1269 | + /** |
|
1270 | + * UTF8-safe wordwrap method: works like the regular wordwrap |
|
1271 | + * PHP function but compatible with UTF8. Otherwise the lengths |
|
1272 | + * are not calculated correctly. |
|
1273 | + * |
|
1274 | + * @param string $str |
|
1275 | + * @param int $width |
|
1276 | + * @param string $break |
|
1277 | + * @param bool $cut |
|
1278 | + * @return string |
|
1279 | + */ |
|
1280 | 1280 | public static function wordwrap(string $str, int $width = 75, string $break = "\n", bool $cut = false) : string |
1281 | 1281 | { |
1282 | 1282 | $wrapper = new ConvertHelper_WordWrapper(); |
@@ -1288,27 +1288,27 @@ discard block |
||
1288 | 1288 | ->wrapText($str); |
1289 | 1289 | } |
1290 | 1290 | |
1291 | - /** |
|
1292 | - * Calculates the byte length of a string, taking into |
|
1293 | - * account any unicode characters. |
|
1294 | - * |
|
1295 | - * @param string $string |
|
1296 | - * @return int |
|
1297 | - * @see https://stackoverflow.com/a/9718273/2298192 |
|
1298 | - */ |
|
1291 | + /** |
|
1292 | + * Calculates the byte length of a string, taking into |
|
1293 | + * account any unicode characters. |
|
1294 | + * |
|
1295 | + * @param string $string |
|
1296 | + * @return int |
|
1297 | + * @see https://stackoverflow.com/a/9718273/2298192 |
|
1298 | + */ |
|
1299 | 1299 | public static function string2bytes($string) |
1300 | 1300 | { |
1301 | 1301 | return mb_strlen($string, '8bit'); |
1302 | 1302 | } |
1303 | 1303 | |
1304 | - /** |
|
1305 | - * Creates a short, 8-character long hash for the specified string. |
|
1306 | - * |
|
1307 | - * WARNING: Not cryptographically safe. |
|
1308 | - * |
|
1309 | - * @param string $string |
|
1310 | - * @return string |
|
1311 | - */ |
|
1304 | + /** |
|
1305 | + * Creates a short, 8-character long hash for the specified string. |
|
1306 | + * |
|
1307 | + * WARNING: Not cryptographically safe. |
|
1308 | + * |
|
1309 | + * @param string $string |
|
1310 | + * @return string |
|
1311 | + */ |
|
1312 | 1312 | public static function string2shortHash($string) |
1313 | 1313 | { |
1314 | 1314 | return hash('crc32', $string, false); |
@@ -1334,40 +1334,40 @@ discard block |
||
1334 | 1334 | return ConvertHelper_ThrowableInfo::fromThrowable($e); |
1335 | 1335 | } |
1336 | 1336 | |
1337 | - /** |
|
1338 | - * Parses the specified query string like the native |
|
1339 | - * function <code>parse_str</code>, without the key |
|
1340 | - * naming limitations. |
|
1341 | - * |
|
1342 | - * Using parse_str, dots or spaces in key names are |
|
1343 | - * replaced by underscores. This method keeps all names |
|
1344 | - * intact. |
|
1345 | - * |
|
1346 | - * It still uses the parse_str implementation as it |
|
1347 | - * is tested and tried, but fixes the parameter names |
|
1348 | - * after parsing, as needed. |
|
1349 | - * |
|
1350 | - * @param string $queryString |
|
1351 | - * @return array |
|
1352 | - * @see ConvertHelper_QueryParser |
|
1353 | - */ |
|
1337 | + /** |
|
1338 | + * Parses the specified query string like the native |
|
1339 | + * function <code>parse_str</code>, without the key |
|
1340 | + * naming limitations. |
|
1341 | + * |
|
1342 | + * Using parse_str, dots or spaces in key names are |
|
1343 | + * replaced by underscores. This method keeps all names |
|
1344 | + * intact. |
|
1345 | + * |
|
1346 | + * It still uses the parse_str implementation as it |
|
1347 | + * is tested and tried, but fixes the parameter names |
|
1348 | + * after parsing, as needed. |
|
1349 | + * |
|
1350 | + * @param string $queryString |
|
1351 | + * @return array |
|
1352 | + * @see ConvertHelper_QueryParser |
|
1353 | + */ |
|
1354 | 1354 | public static function parseQueryString(string $queryString) : array |
1355 | 1355 | { |
1356 | 1356 | $parser = new ConvertHelper_QueryParser(); |
1357 | 1357 | return $parser->parse($queryString); |
1358 | 1358 | } |
1359 | 1359 | |
1360 | - /** |
|
1361 | - * Searches for needle in the specified string, and returns a list |
|
1362 | - * of all occurrences, including the matched string. The matched |
|
1363 | - * string is useful when doing a case insensitive search, as it |
|
1364 | - * shows the exact matched case of needle. |
|
1365 | - * |
|
1366 | - * @param string $needle |
|
1367 | - * @param string $haystack |
|
1368 | - * @param bool $caseInsensitive |
|
1369 | - * @return ConvertHelper_StringMatch[] |
|
1370 | - */ |
|
1360 | + /** |
|
1361 | + * Searches for needle in the specified string, and returns a list |
|
1362 | + * of all occurrences, including the matched string. The matched |
|
1363 | + * string is useful when doing a case insensitive search, as it |
|
1364 | + * shows the exact matched case of needle. |
|
1365 | + * |
|
1366 | + * @param string $needle |
|
1367 | + * @param string $haystack |
|
1368 | + * @param bool $caseInsensitive |
|
1369 | + * @return ConvertHelper_StringMatch[] |
|
1370 | + */ |
|
1371 | 1371 | public static function findString(string $needle, string $haystack, bool $caseInsensitive=false) |
1372 | 1372 | { |
1373 | 1373 | if($needle === '') { |
@@ -1393,14 +1393,14 @@ discard block |
||
1393 | 1393 | return $positions; |
1394 | 1394 | } |
1395 | 1395 | |
1396 | - /** |
|
1397 | - * Like explode, but trims all entries, and removes |
|
1398 | - * empty entries from the resulting array. |
|
1399 | - * |
|
1400 | - * @param string $delimiter |
|
1401 | - * @param string $string |
|
1402 | - * @return string[] |
|
1403 | - */ |
|
1396 | + /** |
|
1397 | + * Like explode, but trims all entries, and removes |
|
1398 | + * empty entries from the resulting array. |
|
1399 | + * |
|
1400 | + * @param string $delimiter |
|
1401 | + * @param string $string |
|
1402 | + * @return string[] |
|
1403 | + */ |
|
1404 | 1404 | public static function explodeTrim(string $delimiter, string $string) : array |
1405 | 1405 | { |
1406 | 1406 | if(empty($string) || empty($delimiter)) { |
@@ -1422,12 +1422,12 @@ discard block |
||
1422 | 1422 | |
1423 | 1423 | protected static $eolChars; |
1424 | 1424 | |
1425 | - /** |
|
1426 | - * Detects the most used end-of-line character in the subject string. |
|
1427 | - * |
|
1428 | - * @param string $str The string to check. |
|
1429 | - * @return NULL|ConvertHelper_EOL The detected EOL instance, or NULL if none has been detected. |
|
1430 | - */ |
|
1425 | + /** |
|
1426 | + * Detects the most used end-of-line character in the subject string. |
|
1427 | + * |
|
1428 | + * @param string $str The string to check. |
|
1429 | + * @return NULL|ConvertHelper_EOL The detected EOL instance, or NULL if none has been detected. |
|
1430 | + */ |
|
1431 | 1431 | public static function detectEOLCharacter(string $subjectString) : ?ConvertHelper_EOL |
1432 | 1432 | { |
1433 | 1433 | if(empty($subjectString)) { |
@@ -1439,27 +1439,27 @@ discard block |
||
1439 | 1439 | $cr = chr((int)hexdec('0d')); |
1440 | 1440 | $lf = chr((int)hexdec('0a')); |
1441 | 1441 | |
1442 | - self::$eolChars = array( |
|
1443 | - array( |
|
1444 | - 'char' => $cr.$lf, |
|
1445 | - 'type' => ConvertHelper_EOL::TYPE_CRLF, |
|
1446 | - 'description' => t('Carriage return followed by a line feed'), |
|
1447 | - ), |
|
1448 | - array( |
|
1449 | - 'char' => $lf.$cr, |
|
1450 | - 'type' => ConvertHelper_EOL::TYPE_LFCR, |
|
1451 | - 'description' => t('Line feed followed by a carriage return'), |
|
1452 | - ), |
|
1453 | - array( |
|
1454 | - 'char' => $lf, |
|
1455 | - 'type' => ConvertHelper_EOL::TYPE_LF, |
|
1456 | - 'description' => t('Line feed'), |
|
1457 | - ), |
|
1458 | - array( |
|
1459 | - 'char' => $cr, |
|
1460 | - 'type' => ConvertHelper_EOL::TYPE_CR, |
|
1461 | - 'description' => t('Carriage Return'), |
|
1462 | - ), |
|
1442 | + self::$eolChars = array( |
|
1443 | + array( |
|
1444 | + 'char' => $cr.$lf, |
|
1445 | + 'type' => ConvertHelper_EOL::TYPE_CRLF, |
|
1446 | + 'description' => t('Carriage return followed by a line feed'), |
|
1447 | + ), |
|
1448 | + array( |
|
1449 | + 'char' => $lf.$cr, |
|
1450 | + 'type' => ConvertHelper_EOL::TYPE_LFCR, |
|
1451 | + 'description' => t('Line feed followed by a carriage return'), |
|
1452 | + ), |
|
1453 | + array( |
|
1454 | + 'char' => $lf, |
|
1455 | + 'type' => ConvertHelper_EOL::TYPE_LF, |
|
1456 | + 'description' => t('Line feed'), |
|
1457 | + ), |
|
1458 | + array( |
|
1459 | + 'char' => $cr, |
|
1460 | + 'type' => ConvertHelper_EOL::TYPE_CR, |
|
1461 | + 'description' => t('Carriage Return'), |
|
1462 | + ), |
|
1463 | 1463 | ); |
1464 | 1464 | } |
1465 | 1465 | |
@@ -1487,13 +1487,13 @@ discard block |
||
1487 | 1487 | ); |
1488 | 1488 | } |
1489 | 1489 | |
1490 | - /** |
|
1491 | - * Removes the specified keys from the target array, |
|
1492 | - * if they exist. |
|
1493 | - * |
|
1494 | - * @param array $array |
|
1495 | - * @param array $keys |
|
1496 | - */ |
|
1490 | + /** |
|
1491 | + * Removes the specified keys from the target array, |
|
1492 | + * if they exist. |
|
1493 | + * |
|
1494 | + * @param array $array |
|
1495 | + * @param array $keys |
|
1496 | + */ |
|
1497 | 1497 | public static function arrayRemoveKeys(array &$array, array $keys) : void |
1498 | 1498 | { |
1499 | 1499 | foreach($keys as $key) |
@@ -1504,13 +1504,13 @@ discard block |
||
1504 | 1504 | } |
1505 | 1505 | } |
1506 | 1506 | |
1507 | - /** |
|
1508 | - * Checks if the specified variable is an integer or a string containing an integer. |
|
1509 | - * Accepts both positive and negative integers. |
|
1510 | - * |
|
1511 | - * @param mixed $value |
|
1512 | - * @return bool |
|
1513 | - */ |
|
1507 | + /** |
|
1508 | + * Checks if the specified variable is an integer or a string containing an integer. |
|
1509 | + * Accepts both positive and negative integers. |
|
1510 | + * |
|
1511 | + * @param mixed $value |
|
1512 | + * @return bool |
|
1513 | + */ |
|
1514 | 1514 | public static function isInteger($value) : bool |
1515 | 1515 | { |
1516 | 1516 | if(is_int($value)) { |
@@ -1530,15 +1530,15 @@ discard block |
||
1530 | 1530 | return false; |
1531 | 1531 | } |
1532 | 1532 | |
1533 | - /** |
|
1534 | - * Converts an amount of seconds to a DateInterval object. |
|
1535 | - * |
|
1536 | - * @param int $seconds |
|
1537 | - * @return \DateInterval |
|
1538 | - * @throws ConvertHelper_Exception If the date interval cannot be created. |
|
1539 | - * |
|
1540 | - * @see ConvertHelper::ERROR_CANNOT_GET_DATE_DIFF |
|
1541 | - */ |
|
1533 | + /** |
|
1534 | + * Converts an amount of seconds to a DateInterval object. |
|
1535 | + * |
|
1536 | + * @param int $seconds |
|
1537 | + * @return \DateInterval |
|
1538 | + * @throws ConvertHelper_Exception If the date interval cannot be created. |
|
1539 | + * |
|
1540 | + * @see ConvertHelper::ERROR_CANNOT_GET_DATE_DIFF |
|
1541 | + */ |
|
1542 | 1542 | public static function seconds2interval(int $seconds) : \DateInterval |
1543 | 1543 | { |
1544 | 1544 | return ConvertHelper_DateInterval::fromSeconds($seconds)->getInterval(); |