@@ -162,41 +162,41 @@ discard block |
||
162 | 162 | return implode(', ', $tokens) . ' ' . t('and') . ' ' . $last; |
163 | 163 | } |
164 | 164 | |
165 | - /** |
|
166 | - * Converts a timestamp into an easily understandable |
|
167 | - * format, e.g. "2 hours", "1 day", "3 months" |
|
168 | - * |
|
169 | - * If you set the date to parameter, the difference |
|
170 | - * will be calculated between the two dates and not |
|
171 | - * the current time. |
|
172 | - * |
|
173 | - * @param integer|\DateTime $datefrom |
|
174 | - * @param integer|\DateTime $dateto |
|
175 | - * @return string |
|
176 | - */ |
|
165 | + /** |
|
166 | + * Converts a timestamp into an easily understandable |
|
167 | + * format, e.g. "2 hours", "1 day", "3 months" |
|
168 | + * |
|
169 | + * If you set the date to parameter, the difference |
|
170 | + * will be calculated between the two dates and not |
|
171 | + * the current time. |
|
172 | + * |
|
173 | + * @param integer|\DateTime $datefrom |
|
174 | + * @param integer|\DateTime $dateto |
|
175 | + * @return string |
|
176 | + */ |
|
177 | 177 | public static function duration2string($datefrom, $dateto = -1) : string |
178 | 178 | { |
179 | - $converter = new ConvertHelper_DurationConverter(); |
|
179 | + $converter = new ConvertHelper_DurationConverter(); |
|
180 | 180 | |
181 | - if($datefrom instanceof \DateTime) |
|
182 | - { |
|
183 | - $converter->setDateFrom($datefrom); |
|
184 | - } |
|
185 | - else |
|
186 | - { |
|
187 | - $converter->setDateFrom(self::timestamp2date($datefrom)); |
|
188 | - } |
|
181 | + if($datefrom instanceof \DateTime) |
|
182 | + { |
|
183 | + $converter->setDateFrom($datefrom); |
|
184 | + } |
|
185 | + else |
|
186 | + { |
|
187 | + $converter->setDateFrom(self::timestamp2date($datefrom)); |
|
188 | + } |
|
189 | 189 | |
190 | - if($dateto instanceof \DateTime) |
|
191 | - { |
|
192 | - $converter->setDateTo($dateto); |
|
193 | - } |
|
194 | - else if($dateto > 0) |
|
195 | - { |
|
196 | - $converter->setDateTo(self::timestamp2date($dateto)); |
|
197 | - } |
|
190 | + if($dateto instanceof \DateTime) |
|
191 | + { |
|
192 | + $converter->setDateTo($dateto); |
|
193 | + } |
|
194 | + else if($dateto > 0) |
|
195 | + { |
|
196 | + $converter->setDateTo(self::timestamp2date($dateto)); |
|
197 | + } |
|
198 | 198 | |
199 | - return $converter->convert(); |
|
199 | + return $converter->convert(); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | /** |
@@ -269,16 +269,16 @@ discard block |
||
269 | 269 | return $bytes . ' ' . t('B'); |
270 | 270 | } |
271 | 271 | |
272 | - /** |
|
273 | - * Cuts a text to the specified length if it is longer than the |
|
274 | - * target length. Appends a text to signify it has been cut at |
|
275 | - * the end of the string. |
|
276 | - * |
|
277 | - * @param string $text |
|
278 | - * @param int $targetLength |
|
279 | - * @param string $append |
|
280 | - * @return string |
|
281 | - */ |
|
272 | + /** |
|
273 | + * Cuts a text to the specified length if it is longer than the |
|
274 | + * target length. Appends a text to signify it has been cut at |
|
275 | + * the end of the string. |
|
276 | + * |
|
277 | + * @param string $text |
|
278 | + * @param int $targetLength |
|
279 | + * @param string $append |
|
280 | + * @return string |
|
281 | + */ |
|
282 | 282 | public static function text_cut(string $text, int $targetLength, string $append = '...') : string |
283 | 283 | { |
284 | 284 | $length = mb_strlen($text); |
@@ -348,27 +348,27 @@ discard block |
||
348 | 348 | return self::$booleanStrings[$string]; |
349 | 349 | } |
350 | 350 | |
351 | - /** |
|
352 | - * Whether the specified string is a boolean string or boolean value. |
|
353 | - * Alias for {@link ConvertHelper::isBoolean()}. |
|
354 | - * |
|
355 | - * @param mixed $string |
|
356 | - * @return bool |
|
357 | - * @deprecated |
|
358 | - * @see ConvertHelper::isBoolean() |
|
359 | - */ |
|
351 | + /** |
|
352 | + * Whether the specified string is a boolean string or boolean value. |
|
353 | + * Alias for {@link ConvertHelper::isBoolean()}. |
|
354 | + * |
|
355 | + * @param mixed $string |
|
356 | + * @return bool |
|
357 | + * @deprecated |
|
358 | + * @see ConvertHelper::isBoolean() |
|
359 | + */ |
|
360 | 360 | public static function isBooleanString($string) : bool |
361 | 361 | { |
362 | 362 | return self::isBoolean($string); |
363 | 363 | } |
364 | 364 | |
365 | - /** |
|
366 | - * Alias for the {@\AppUtils\XMLHelper::string2xml()} method. |
|
367 | - * |
|
368 | - * @param string $text |
|
369 | - * @return string |
|
370 | - * @deprecated |
|
371 | - */ |
|
365 | + /** |
|
366 | + * Alias for the {@\AppUtils\XMLHelper::string2xml()} method. |
|
367 | + * |
|
368 | + * @param string $text |
|
369 | + * @return string |
|
370 | + * @deprecated |
|
371 | + */ |
|
372 | 372 | public static function text_makeXMLCompliant($text) |
373 | 373 | { |
374 | 374 | return XMLHelper::string2xml($text); |
@@ -470,13 +470,13 @@ discard block |
||
470 | 470 | return $translit->convert($string); |
471 | 471 | } |
472 | 472 | |
473 | - /** |
|
474 | - * Retrieves the HEX character codes for all control |
|
475 | - * characters that the {@link stripControlCharacters()} |
|
476 | - * method will remove. |
|
477 | - * |
|
478 | - * @return string[] |
|
479 | - */ |
|
473 | + /** |
|
474 | + * Retrieves the HEX character codes for all control |
|
475 | + * characters that the {@link stripControlCharacters()} |
|
476 | + * method will remove. |
|
477 | + * |
|
478 | + * @return string[] |
|
479 | + */ |
|
480 | 480 | public static function getControlCharactersAsHex() |
481 | 481 | { |
482 | 482 | $hexAlphabet = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); |
@@ -512,13 +512,13 @@ discard block |
||
512 | 512 | return $stack; |
513 | 513 | } |
514 | 514 | |
515 | - /** |
|
516 | - * Retrieves an array of all control characters that |
|
517 | - * the {@link stripControlCharacters()} method will |
|
518 | - * remove, as the actual UTF-8 characters. |
|
519 | - * |
|
520 | - * @return string[] |
|
521 | - */ |
|
515 | + /** |
|
516 | + * Retrieves an array of all control characters that |
|
517 | + * the {@link stripControlCharacters()} method will |
|
518 | + * remove, as the actual UTF-8 characters. |
|
519 | + * |
|
520 | + * @return string[] |
|
521 | + */ |
|
522 | 522 | public static function getControlCharactersAsUTF8() |
523 | 523 | { |
524 | 524 | $chars = self::getControlCharactersAsHex(); |
@@ -531,12 +531,12 @@ discard block |
||
531 | 531 | return $result; |
532 | 532 | } |
533 | 533 | |
534 | - /** |
|
535 | - * Retrieves all control characters as JSON encoded |
|
536 | - * characters, e.g. "\u200b". |
|
537 | - * |
|
538 | - * @return string[] |
|
539 | - */ |
|
534 | + /** |
|
535 | + * Retrieves all control characters as JSON encoded |
|
536 | + * characters, e.g. "\u200b". |
|
537 | + * |
|
538 | + * @return string[] |
|
539 | + */ |
|
540 | 540 | public static function getControlCharactersAsJSON() |
541 | 541 | { |
542 | 542 | $chars = self::getControlCharactersAsHex(); |
@@ -593,20 +593,20 @@ discard block |
||
593 | 593 | return preg_replace(self::$controlCharsRegex, '', $string); |
594 | 594 | } |
595 | 595 | |
596 | - /** |
|
597 | - * Converts a unicode character to the PHPO notation. |
|
598 | - * |
|
599 | - * Example: |
|
600 | - * |
|
601 | - * <pre>unicodeChar2php('"\u0000"')</pre> |
|
602 | - * |
|
603 | - * Returns |
|
604 | - * |
|
605 | - * <pre>\x0</pre> |
|
606 | - * |
|
607 | - * @param string $unicodeChar |
|
608 | - * @return string |
|
609 | - */ |
|
596 | + /** |
|
597 | + * Converts a unicode character to the PHPO notation. |
|
598 | + * |
|
599 | + * Example: |
|
600 | + * |
|
601 | + * <pre>unicodeChar2php('"\u0000"')</pre> |
|
602 | + * |
|
603 | + * Returns |
|
604 | + * |
|
605 | + * <pre>\x0</pre> |
|
606 | + * |
|
607 | + * @param string $unicodeChar |
|
608 | + * @return string |
|
609 | + */ |
|
610 | 610 | public static function unicodeChar2php($unicodeChar) |
611 | 611 | { |
612 | 612 | $unicodeChar = json_decode($unicodeChar); |
@@ -729,25 +729,25 @@ discard block |
||
729 | 729 | return 'false'; |
730 | 730 | } |
731 | 731 | |
732 | - /** |
|
733 | - * Converts an associative array with attribute name > value pairs |
|
734 | - * to an attribute string that can be used in an HTML tag. Empty |
|
735 | - * attribute values are ignored. |
|
736 | - * |
|
737 | - * Example: |
|
738 | - * |
|
739 | - * array2attributeString(array( |
|
740 | - * 'id' => 45, |
|
741 | - * 'href' => 'http://www.mistralys.com' |
|
742 | - * )); |
|
743 | - * |
|
744 | - * Result: |
|
745 | - * |
|
746 | - * id="45" href="http://www.mistralys.com" |
|
747 | - * |
|
748 | - * @param array $array |
|
749 | - * @return string |
|
750 | - */ |
|
732 | + /** |
|
733 | + * Converts an associative array with attribute name > value pairs |
|
734 | + * to an attribute string that can be used in an HTML tag. Empty |
|
735 | + * attribute values are ignored. |
|
736 | + * |
|
737 | + * Example: |
|
738 | + * |
|
739 | + * array2attributeString(array( |
|
740 | + * 'id' => 45, |
|
741 | + * 'href' => 'http://www.mistralys.com' |
|
742 | + * )); |
|
743 | + * |
|
744 | + * Result: |
|
745 | + * |
|
746 | + * id="45" href="http://www.mistralys.com" |
|
747 | + * |
|
748 | + * @param array $array |
|
749 | + * @return string |
|
750 | + */ |
|
751 | 751 | public static function array2attributeString($array) |
752 | 752 | { |
753 | 753 | $tokens = array(); |
@@ -766,14 +766,14 @@ discard block |
||
766 | 766 | return ' '.implode(' ', $tokens); |
767 | 767 | } |
768 | 768 | |
769 | - /** |
|
770 | - * Converts a string so it can safely be used in a javascript |
|
771 | - * statement in an HTML tag: uses single quotes around the string |
|
772 | - * and encodes all special characters as needed. |
|
773 | - * |
|
774 | - * @param string $string |
|
775 | - * @return string |
|
776 | - */ |
|
769 | + /** |
|
770 | + * Converts a string so it can safely be used in a javascript |
|
771 | + * statement in an HTML tag: uses single quotes around the string |
|
772 | + * and encodes all special characters as needed. |
|
773 | + * |
|
774 | + * @param string $string |
|
775 | + * @return string |
|
776 | + */ |
|
777 | 777 | public static function string2attributeJS($string, $quoted=true) |
778 | 778 | { |
779 | 779 | $converted = addslashes(htmlspecialchars(strip_tags($string), ENT_QUOTES, 'UTF-8')); |
@@ -784,15 +784,15 @@ discard block |
||
784 | 784 | return $converted; |
785 | 785 | } |
786 | 786 | |
787 | - /** |
|
788 | - * Checks if the specified string is a boolean value, which |
|
789 | - * includes string representations of boolean values, like |
|
790 | - * <code>yes</code> or <code>no</code>, and <code>true</code> |
|
791 | - * or <code>false</code>. |
|
792 | - * |
|
793 | - * @param mixed $value |
|
794 | - * @return boolean |
|
795 | - */ |
|
787 | + /** |
|
788 | + * Checks if the specified string is a boolean value, which |
|
789 | + * includes string representations of boolean values, like |
|
790 | + * <code>yes</code> or <code>no</code>, and <code>true</code> |
|
791 | + * or <code>false</code>. |
|
792 | + * |
|
793 | + * @param mixed $value |
|
794 | + * @return boolean |
|
795 | + */ |
|
796 | 796 | public static function isBoolean($value) : bool |
797 | 797 | { |
798 | 798 | if(is_bool($value)) { |
@@ -806,12 +806,12 @@ discard block |
||
806 | 806 | return array_key_exists($value, self::$booleanStrings); |
807 | 807 | } |
808 | 808 | |
809 | - /** |
|
810 | - * Converts an associative array to an HTML style attribute value string. |
|
811 | - * |
|
812 | - * @param array $subject |
|
813 | - * @return string |
|
814 | - */ |
|
809 | + /** |
|
810 | + * Converts an associative array to an HTML style attribute value string. |
|
811 | + * |
|
812 | + * @param array $subject |
|
813 | + * @return string |
|
814 | + */ |
|
815 | 815 | public static function array2styleString(array $subject) : string |
816 | 816 | { |
817 | 817 | $tokens = array(); |
@@ -822,23 +822,23 @@ discard block |
||
822 | 822 | return implode(';', $tokens); |
823 | 823 | } |
824 | 824 | |
825 | - /** |
|
826 | - * Converts a DateTime object to a timestamp, which |
|
827 | - * is PHP 5.2 compatible. |
|
828 | - * |
|
829 | - * @param \DateTime $date |
|
830 | - * @return integer |
|
831 | - */ |
|
825 | + /** |
|
826 | + * Converts a DateTime object to a timestamp, which |
|
827 | + * is PHP 5.2 compatible. |
|
828 | + * |
|
829 | + * @param \DateTime $date |
|
830 | + * @return integer |
|
831 | + */ |
|
832 | 832 | public static function date2timestamp(\DateTime $date) : int |
833 | 833 | { |
834 | 834 | return (int)$date->format('U'); |
835 | 835 | } |
836 | 836 | |
837 | - /** |
|
838 | - * Converts a timestamp into a DateTime instance. |
|
839 | - * @param int $timestamp |
|
840 | - * @return \DateTime |
|
841 | - */ |
|
837 | + /** |
|
838 | + * Converts a timestamp into a DateTime instance. |
|
839 | + * @param int $timestamp |
|
840 | + * @return \DateTime |
|
841 | + */ |
|
842 | 842 | public static function timestamp2date(int $timestamp) : \DateTime |
843 | 843 | { |
844 | 844 | $date = new \DateTime(); |
@@ -846,50 +846,50 @@ discard block |
||
846 | 846 | return $date; |
847 | 847 | } |
848 | 848 | |
849 | - /** |
|
850 | - * Strips an absolute path to a file within the application |
|
851 | - * to make the path relative to the application root path. |
|
852 | - * |
|
853 | - * @param string $path |
|
854 | - * @return string |
|
855 | - * |
|
856 | - * @see FileHelper::relativizePath() |
|
857 | - * @see FileHelper::relativizePathByDepth() |
|
858 | - */ |
|
849 | + /** |
|
850 | + * Strips an absolute path to a file within the application |
|
851 | + * to make the path relative to the application root path. |
|
852 | + * |
|
853 | + * @param string $path |
|
854 | + * @return string |
|
855 | + * |
|
856 | + * @see FileHelper::relativizePath() |
|
857 | + * @see FileHelper::relativizePathByDepth() |
|
858 | + */ |
|
859 | 859 | public static function fileRelativize(string $path) : string |
860 | 860 | { |
861 | 861 | return FileHelper::relativizePathByDepth($path); |
862 | 862 | } |
863 | 863 | |
864 | 864 | /** |
865 | - * Converts a PHP regex to a javascript RegExp object statement. |
|
866 | - * |
|
867 | - * NOTE: This is an alias for the JSHelper's `convertRegex` method. |
|
868 | - * More details are available on its usage there. |
|
869 | - * |
|
870 | - * @param string $regex A PHP preg regex |
|
871 | - * @param string $statementType The type of statement to return: Defaults to a statement to create a RegExp object. |
|
872 | - * @return array|string Depending on the specified return type. |
|
873 | - * |
|
874 | - * @see JSHelper::buildRegexStatement() |
|
875 | - */ |
|
865 | + * Converts a PHP regex to a javascript RegExp object statement. |
|
866 | + * |
|
867 | + * NOTE: This is an alias for the JSHelper's `convertRegex` method. |
|
868 | + * More details are available on its usage there. |
|
869 | + * |
|
870 | + * @param string $regex A PHP preg regex |
|
871 | + * @param string $statementType The type of statement to return: Defaults to a statement to create a RegExp object. |
|
872 | + * @return array|string Depending on the specified return type. |
|
873 | + * |
|
874 | + * @see JSHelper::buildRegexStatement() |
|
875 | + */ |
|
876 | 876 | public static function regex2js(string $regex, string $statementType=JSHelper::JS_REGEX_OBJECT) |
877 | 877 | { |
878 | 878 | return JSHelper::buildRegexStatement($regex, $statementType); |
879 | 879 | } |
880 | 880 | |
881 | - /** |
|
882 | - * Converts the specified variable to JSON. Works just |
|
883 | - * like the native `json_encode` method, except that it |
|
884 | - * will trigger an exception on failure, which has the |
|
885 | - * json error details included in its developer details. |
|
886 | - * |
|
887 | - * @param mixed $variable |
|
888 | - * @param int|NULL $options JSON encode options. |
|
889 | - * @param int|NULL $depth |
|
890 | - * @throws ConvertHelper_Exception |
|
891 | - * @return string |
|
892 | - */ |
|
881 | + /** |
|
882 | + * Converts the specified variable to JSON. Works just |
|
883 | + * like the native `json_encode` method, except that it |
|
884 | + * will trigger an exception on failure, which has the |
|
885 | + * json error details included in its developer details. |
|
886 | + * |
|
887 | + * @param mixed $variable |
|
888 | + * @param int|NULL $options JSON encode options. |
|
889 | + * @param int|NULL $depth |
|
890 | + * @throws ConvertHelper_Exception |
|
891 | + * @return string |
|
892 | + */ |
|
893 | 893 | public static function var2json($variable, int $options=0, int $depth=512) : string |
894 | 894 | { |
895 | 895 | $result = json_encode($variable, $options, $depth); |
@@ -910,12 +910,12 @@ discard block |
||
910 | 910 | ); |
911 | 911 | } |
912 | 912 | |
913 | - /** |
|
914 | - * Strips all known UTF byte order marks from the specified string. |
|
915 | - * |
|
916 | - * @param string $string |
|
917 | - * @return string |
|
918 | - */ |
|
913 | + /** |
|
914 | + * Strips all known UTF byte order marks from the specified string. |
|
915 | + * |
|
916 | + * @param string $string |
|
917 | + * @return string |
|
918 | + */ |
|
919 | 919 | public static function stripUTFBom($string) |
920 | 920 | { |
921 | 921 | $boms = FileHelper::getUTFBOMs(); |
@@ -930,13 +930,13 @@ discard block |
||
930 | 930 | return $string; |
931 | 931 | } |
932 | 932 | |
933 | - /** |
|
934 | - * Converts a string to valid utf8, regardless |
|
935 | - * of the string's encoding(s). |
|
936 | - * |
|
937 | - * @param string $string |
|
938 | - * @return string |
|
939 | - */ |
|
933 | + /** |
|
934 | + * Converts a string to valid utf8, regardless |
|
935 | + * of the string's encoding(s). |
|
936 | + * |
|
937 | + * @param string $string |
|
938 | + * @return string |
|
939 | + */ |
|
940 | 940 | public static function string2utf8($string) |
941 | 941 | { |
942 | 942 | if(!self::isStringASCII($string)) { |
@@ -946,15 +946,15 @@ discard block |
||
946 | 946 | return $string; |
947 | 947 | } |
948 | 948 | |
949 | - /** |
|
950 | - * Checks whether the specified string is an ASCII |
|
951 | - * string, without any special or UTF8 characters. |
|
952 | - * Note: empty strings and NULL are considered ASCII. |
|
953 | - * Any variable types other than strings are not. |
|
954 | - * |
|
955 | - * @param mixed $string |
|
956 | - * @return boolean |
|
957 | - */ |
|
949 | + /** |
|
950 | + * Checks whether the specified string is an ASCII |
|
951 | + * string, without any special or UTF8 characters. |
|
952 | + * Note: empty strings and NULL are considered ASCII. |
|
953 | + * Any variable types other than strings are not. |
|
954 | + * |
|
955 | + * @param mixed $string |
|
956 | + * @return boolean |
|
957 | + */ |
|
958 | 958 | public static function isStringASCII($string) : bool |
959 | 959 | { |
960 | 960 | if($string === '' || $string === NULL) { |
@@ -979,22 +979,22 @@ discard block |
||
979 | 979 | return $url; |
980 | 980 | } |
981 | 981 | |
982 | - /** |
|
983 | - * Calculates a percentage match of the source string with the target string. |
|
984 | - * |
|
985 | - * Options are: |
|
986 | - * |
|
987 | - * - maxLevenshtein, default: 10 |
|
988 | - * Any levenshtein results above this value are ignored. |
|
989 | - * |
|
990 | - * - precision, default: 1 |
|
991 | - * The precision of the percentage float value |
|
992 | - * |
|
993 | - * @param string $source |
|
994 | - * @param string $target |
|
995 | - * @param array $options |
|
996 | - * @return float |
|
997 | - */ |
|
982 | + /** |
|
983 | + * Calculates a percentage match of the source string with the target string. |
|
984 | + * |
|
985 | + * Options are: |
|
986 | + * |
|
987 | + * - maxLevenshtein, default: 10 |
|
988 | + * Any levenshtein results above this value are ignored. |
|
989 | + * |
|
990 | + * - precision, default: 1 |
|
991 | + * The precision of the percentage float value |
|
992 | + * |
|
993 | + * @param string $source |
|
994 | + * @param string $target |
|
995 | + * @param array $options |
|
996 | + * @return float |
|
997 | + */ |
|
998 | 998 | public static function matchString($source, $target, $options=array()) |
999 | 999 | { |
1000 | 1000 | $defaults = array( |
@@ -1078,60 +1078,60 @@ discard block |
||
1078 | 1078 | |
1079 | 1079 | const INTERVAL_SECONDS = 'seconds'; |
1080 | 1080 | |
1081 | - /** |
|
1082 | - * Converts an interval to its total amount of days. |
|
1083 | - * @param \DateInterval $interval |
|
1084 | - * @return int |
|
1085 | - */ |
|
1081 | + /** |
|
1082 | + * Converts an interval to its total amount of days. |
|
1083 | + * @param \DateInterval $interval |
|
1084 | + * @return int |
|
1085 | + */ |
|
1086 | 1086 | public static function interval2days(\DateInterval $interval) : int |
1087 | 1087 | { |
1088 | 1088 | return self::interval2total($interval, self::INTERVAL_DAYS); |
1089 | 1089 | } |
1090 | 1090 | |
1091 | - /** |
|
1092 | - * Converts an interval to its total amount of hours. |
|
1093 | - * @param \DateInterval $interval |
|
1094 | - * @return int |
|
1095 | - */ |
|
1091 | + /** |
|
1092 | + * Converts an interval to its total amount of hours. |
|
1093 | + * @param \DateInterval $interval |
|
1094 | + * @return int |
|
1095 | + */ |
|
1096 | 1096 | public static function interval2hours(\DateInterval $interval) : int |
1097 | 1097 | { |
1098 | 1098 | return self::interval2total($interval, self::INTERVAL_HOURS); |
1099 | 1099 | } |
1100 | 1100 | |
1101 | - /** |
|
1102 | - * Converts an interval to its total amount of minutes. |
|
1103 | - * @param \DateInterval $interval |
|
1104 | - * @return int |
|
1105 | - */ |
|
1101 | + /** |
|
1102 | + * Converts an interval to its total amount of minutes. |
|
1103 | + * @param \DateInterval $interval |
|
1104 | + * @return int |
|
1105 | + */ |
|
1106 | 1106 | public static function interval2minutes(\DateInterval $interval) : int |
1107 | 1107 | { |
1108 | 1108 | return self::interval2total($interval, self::INTERVAL_MINUTES); |
1109 | 1109 | } |
1110 | 1110 | |
1111 | - /** |
|
1112 | - * Converts an interval to its total amount of seconds. |
|
1113 | - * @param \DateInterval $interval |
|
1114 | - * @return int |
|
1115 | - */ |
|
1111 | + /** |
|
1112 | + * Converts an interval to its total amount of seconds. |
|
1113 | + * @param \DateInterval $interval |
|
1114 | + * @return int |
|
1115 | + */ |
|
1116 | 1116 | public static function interval2seconds(\DateInterval $interval) : int |
1117 | 1117 | { |
1118 | 1118 | return self::interval2total($interval, self::INTERVAL_SECONDS); |
1119 | 1119 | } |
1120 | 1120 | |
1121 | - /** |
|
1122 | - * Calculates the total amount of days / hours / minutes or seconds |
|
1123 | - * of a date interval object (depending in the specified units), and |
|
1124 | - * returns the total amount. |
|
1125 | - * |
|
1126 | - * @param \DateInterval $interval |
|
1127 | - * @param string $unit What total value to calculate. |
|
1128 | - * @return integer |
|
1129 | - * |
|
1130 | - * @see ConvertHelper::INTERVAL_SECONDS |
|
1131 | - * @see ConvertHelper::INTERVAL_MINUTES |
|
1132 | - * @see ConvertHelper::INTERVAL_HOURS |
|
1133 | - * @see ConvertHelper::INTERVAL_DAYS |
|
1134 | - */ |
|
1121 | + /** |
|
1122 | + * Calculates the total amount of days / hours / minutes or seconds |
|
1123 | + * of a date interval object (depending in the specified units), and |
|
1124 | + * returns the total amount. |
|
1125 | + * |
|
1126 | + * @param \DateInterval $interval |
|
1127 | + * @param string $unit What total value to calculate. |
|
1128 | + * @return integer |
|
1129 | + * |
|
1130 | + * @see ConvertHelper::INTERVAL_SECONDS |
|
1131 | + * @see ConvertHelper::INTERVAL_MINUTES |
|
1132 | + * @see ConvertHelper::INTERVAL_HOURS |
|
1133 | + * @see ConvertHelper::INTERVAL_DAYS |
|
1134 | + */ |
|
1135 | 1135 | public static function interval2total(\DateInterval $interval, $unit=self::INTERVAL_SECONDS) : int |
1136 | 1136 | { |
1137 | 1137 | $total = $interval->format('%a'); |
@@ -1171,13 +1171,13 @@ discard block |
||
1171 | 1171 | 'Sunday' |
1172 | 1172 | ); |
1173 | 1173 | |
1174 | - /** |
|
1175 | - * Converts a date to the corresponding day name. |
|
1176 | - * |
|
1177 | - * @param \DateTime $date |
|
1178 | - * @param string $short |
|
1179 | - * @return string|NULL |
|
1180 | - */ |
|
1174 | + /** |
|
1175 | + * Converts a date to the corresponding day name. |
|
1176 | + * |
|
1177 | + * @param \DateTime $date |
|
1178 | + * @param string $short |
|
1179 | + * @return string|NULL |
|
1180 | + */ |
|
1181 | 1181 | public static function date2dayName(\DateTime $date, $short=false) |
1182 | 1182 | { |
1183 | 1183 | $day = $date->format('l'); |
@@ -1192,21 +1192,21 @@ discard block |
||
1192 | 1192 | return null; |
1193 | 1193 | } |
1194 | 1194 | |
1195 | - /** |
|
1196 | - * Retrieves a list of english day names. |
|
1197 | - * @return string[] |
|
1198 | - */ |
|
1195 | + /** |
|
1196 | + * Retrieves a list of english day names. |
|
1197 | + * @return string[] |
|
1198 | + */ |
|
1199 | 1199 | public static function getDayNamesInvariant() |
1200 | 1200 | { |
1201 | 1201 | return self::$daysInvariant; |
1202 | 1202 | } |
1203 | 1203 | |
1204 | - /** |
|
1205 | - * Retrieves the day names list for the current locale. |
|
1206 | - * |
|
1207 | - * @param string $short |
|
1208 | - * @return string[] |
|
1209 | - */ |
|
1204 | + /** |
|
1205 | + * Retrieves the day names list for the current locale. |
|
1206 | + * |
|
1207 | + * @param string $short |
|
1208 | + * @return string[] |
|
1209 | + */ |
|
1210 | 1210 | public static function getDayNames($short=false) |
1211 | 1211 | { |
1212 | 1212 | if($short) { |
@@ -1266,16 +1266,16 @@ discard block |
||
1266 | 1266 | return $last; |
1267 | 1267 | } |
1268 | 1268 | |
1269 | - /** |
|
1270 | - * Splits a string into an array of all characters it is composed of. |
|
1271 | - * Unicode character safe. |
|
1272 | - * |
|
1273 | - * NOTE: Spaces and newlines (both \r and \n) are also considered single |
|
1274 | - * characters. |
|
1275 | - * |
|
1276 | - * @param string $string |
|
1277 | - * @return array |
|
1278 | - */ |
|
1269 | + /** |
|
1270 | + * Splits a string into an array of all characters it is composed of. |
|
1271 | + * Unicode character safe. |
|
1272 | + * |
|
1273 | + * NOTE: Spaces and newlines (both \r and \n) are also considered single |
|
1274 | + * characters. |
|
1275 | + * |
|
1276 | + * @param string $string |
|
1277 | + * @return array |
|
1278 | + */ |
|
1279 | 1279 | public static function string2array(string $string) : array |
1280 | 1280 | { |
1281 | 1281 | $result = preg_split('//u', $string, null, PREG_SPLIT_NO_EMPTY); |
@@ -1286,12 +1286,12 @@ discard block |
||
1286 | 1286 | return array(); |
1287 | 1287 | } |
1288 | 1288 | |
1289 | - /** |
|
1290 | - * Checks whether the specified string contains HTML code. |
|
1291 | - * |
|
1292 | - * @param string $string |
|
1293 | - * @return boolean |
|
1294 | - */ |
|
1289 | + /** |
|
1290 | + * Checks whether the specified string contains HTML code. |
|
1291 | + * |
|
1292 | + * @param string $string |
|
1293 | + * @return boolean |
|
1294 | + */ |
|
1295 | 1295 | public static function isStringHTML(string $string) : bool |
1296 | 1296 | { |
1297 | 1297 | if(preg_match('%<[a-z/][\s\S]*>%siU', $string)) { |
@@ -1306,17 +1306,17 @@ discard block |
||
1306 | 1306 | return false; |
1307 | 1307 | } |
1308 | 1308 | |
1309 | - /** |
|
1310 | - * UTF8-safe wordwrap method: works like the regular wordwrap |
|
1311 | - * PHP function but compatible with UTF8. Otherwise the lengths |
|
1312 | - * are not calculated correctly. |
|
1313 | - * |
|
1314 | - * @param string $str |
|
1315 | - * @param int $width |
|
1316 | - * @param string $break |
|
1317 | - * @param bool $cut |
|
1318 | - * @return string |
|
1319 | - */ |
|
1309 | + /** |
|
1310 | + * UTF8-safe wordwrap method: works like the regular wordwrap |
|
1311 | + * PHP function but compatible with UTF8. Otherwise the lengths |
|
1312 | + * are not calculated correctly. |
|
1313 | + * |
|
1314 | + * @param string $str |
|
1315 | + * @param int $width |
|
1316 | + * @param string $break |
|
1317 | + * @param bool $cut |
|
1318 | + * @return string |
|
1319 | + */ |
|
1320 | 1320 | public static function wordwrap(string $str, int $width = 75, string $break = "\n", bool $cut = false) : string |
1321 | 1321 | { |
1322 | 1322 | $wrapper = new ConvertHelper_WordWrapper(); |
@@ -1328,27 +1328,27 @@ discard block |
||
1328 | 1328 | ->wrapText($str); |
1329 | 1329 | } |
1330 | 1330 | |
1331 | - /** |
|
1332 | - * Calculates the byte length of a string, taking into |
|
1333 | - * account any unicode characters. |
|
1334 | - * |
|
1335 | - * @param string $string |
|
1336 | - * @return int |
|
1337 | - * @see https://stackoverflow.com/a/9718273/2298192 |
|
1338 | - */ |
|
1331 | + /** |
|
1332 | + * Calculates the byte length of a string, taking into |
|
1333 | + * account any unicode characters. |
|
1334 | + * |
|
1335 | + * @param string $string |
|
1336 | + * @return int |
|
1337 | + * @see https://stackoverflow.com/a/9718273/2298192 |
|
1338 | + */ |
|
1339 | 1339 | public static function string2bytes($string) |
1340 | 1340 | { |
1341 | 1341 | return mb_strlen($string, '8bit'); |
1342 | 1342 | } |
1343 | 1343 | |
1344 | - /** |
|
1345 | - * Creates a short, 8-character long hash for the specified string. |
|
1346 | - * |
|
1347 | - * WARNING: Not cryptographically safe. |
|
1348 | - * |
|
1349 | - * @param string $string |
|
1350 | - * @return string |
|
1351 | - */ |
|
1344 | + /** |
|
1345 | + * Creates a short, 8-character long hash for the specified string. |
|
1346 | + * |
|
1347 | + * WARNING: Not cryptographically safe. |
|
1348 | + * |
|
1349 | + * @param string $string |
|
1350 | + * @return string |
|
1351 | + */ |
|
1352 | 1352 | public static function string2shortHash($string) |
1353 | 1353 | { |
1354 | 1354 | return hash('crc32', $string, false); |
@@ -1374,40 +1374,40 @@ discard block |
||
1374 | 1374 | return ConvertHelper_ThrowableInfo::fromThrowable($e); |
1375 | 1375 | } |
1376 | 1376 | |
1377 | - /** |
|
1378 | - * Parses the specified query string like the native |
|
1379 | - * function <code>parse_str</code>, without the key |
|
1380 | - * naming limitations. |
|
1381 | - * |
|
1382 | - * Using parse_str, dots or spaces in key names are |
|
1383 | - * replaced by underscores. This method keeps all names |
|
1384 | - * intact. |
|
1385 | - * |
|
1386 | - * It still uses the parse_str implementation as it |
|
1387 | - * is tested and tried, but fixes the parameter names |
|
1388 | - * after parsing, as needed. |
|
1389 | - * |
|
1390 | - * @param string $queryString |
|
1391 | - * @return array |
|
1392 | - * @see ConvertHelper_QueryParser |
|
1393 | - */ |
|
1377 | + /** |
|
1378 | + * Parses the specified query string like the native |
|
1379 | + * function <code>parse_str</code>, without the key |
|
1380 | + * naming limitations. |
|
1381 | + * |
|
1382 | + * Using parse_str, dots or spaces in key names are |
|
1383 | + * replaced by underscores. This method keeps all names |
|
1384 | + * intact. |
|
1385 | + * |
|
1386 | + * It still uses the parse_str implementation as it |
|
1387 | + * is tested and tried, but fixes the parameter names |
|
1388 | + * after parsing, as needed. |
|
1389 | + * |
|
1390 | + * @param string $queryString |
|
1391 | + * @return array |
|
1392 | + * @see ConvertHelper_QueryParser |
|
1393 | + */ |
|
1394 | 1394 | public static function parseQueryString(string $queryString) : array |
1395 | 1395 | { |
1396 | 1396 | $parser = new ConvertHelper_QueryParser(); |
1397 | 1397 | return $parser->parse($queryString); |
1398 | 1398 | } |
1399 | 1399 | |
1400 | - /** |
|
1401 | - * Searches for needle in the specified string, and returns a list |
|
1402 | - * of all occurrences, including the matched string. The matched |
|
1403 | - * string is useful when doing a case insensitive search, as it |
|
1404 | - * shows the exact matched case of needle. |
|
1405 | - * |
|
1406 | - * @param string $needle |
|
1407 | - * @param string $haystack |
|
1408 | - * @param bool $caseInsensitive |
|
1409 | - * @return ConvertHelper_StringMatch[] |
|
1410 | - */ |
|
1400 | + /** |
|
1401 | + * Searches for needle in the specified string, and returns a list |
|
1402 | + * of all occurrences, including the matched string. The matched |
|
1403 | + * string is useful when doing a case insensitive search, as it |
|
1404 | + * shows the exact matched case of needle. |
|
1405 | + * |
|
1406 | + * @param string $needle |
|
1407 | + * @param string $haystack |
|
1408 | + * @param bool $caseInsensitive |
|
1409 | + * @return ConvertHelper_StringMatch[] |
|
1410 | + */ |
|
1411 | 1411 | public static function findString(string $needle, string $haystack, bool $caseInsensitive=false) |
1412 | 1412 | { |
1413 | 1413 | if($needle === '') { |
@@ -1433,14 +1433,14 @@ discard block |
||
1433 | 1433 | return $positions; |
1434 | 1434 | } |
1435 | 1435 | |
1436 | - /** |
|
1437 | - * Like explode, but trims all entries, and removes |
|
1438 | - * empty entries from the resulting array. |
|
1439 | - * |
|
1440 | - * @param string $delimiter |
|
1441 | - * @param string $string |
|
1442 | - * @return string[] |
|
1443 | - */ |
|
1436 | + /** |
|
1437 | + * Like explode, but trims all entries, and removes |
|
1438 | + * empty entries from the resulting array. |
|
1439 | + * |
|
1440 | + * @param string $delimiter |
|
1441 | + * @param string $string |
|
1442 | + * @return string[] |
|
1443 | + */ |
|
1444 | 1444 | public static function explodeTrim(string $delimiter, string $string) : array |
1445 | 1445 | { |
1446 | 1446 | if(empty($string) || empty($delimiter)) { |
@@ -1462,12 +1462,12 @@ discard block |
||
1462 | 1462 | |
1463 | 1463 | protected static $eolChars; |
1464 | 1464 | |
1465 | - /** |
|
1466 | - * Detects the most used end-of-line character in the subject string. |
|
1467 | - * |
|
1468 | - * @param string $str The string to check. |
|
1469 | - * @return NULL|ConvertHelper_EOL The detected EOL instance, or NULL if none has been detected. |
|
1470 | - */ |
|
1465 | + /** |
|
1466 | + * Detects the most used end-of-line character in the subject string. |
|
1467 | + * |
|
1468 | + * @param string $str The string to check. |
|
1469 | + * @return NULL|ConvertHelper_EOL The detected EOL instance, or NULL if none has been detected. |
|
1470 | + */ |
|
1471 | 1471 | public static function detectEOLCharacter(string $subjectString) : ?ConvertHelper_EOL |
1472 | 1472 | { |
1473 | 1473 | if(empty($subjectString)) { |
@@ -1479,27 +1479,27 @@ discard block |
||
1479 | 1479 | $cr = chr((int)hexdec('0d')); |
1480 | 1480 | $lf = chr((int)hexdec('0a')); |
1481 | 1481 | |
1482 | - self::$eolChars = array( |
|
1483 | - array( |
|
1484 | - 'char' => $cr.$lf, |
|
1485 | - 'type' => ConvertHelper_EOL::TYPE_CRLF, |
|
1486 | - 'description' => t('Carriage return followed by a line feed'), |
|
1487 | - ), |
|
1488 | - array( |
|
1489 | - 'char' => $lf.$cr, |
|
1490 | - 'type' => ConvertHelper_EOL::TYPE_LFCR, |
|
1491 | - 'description' => t('Line feed followed by a carriage return'), |
|
1492 | - ), |
|
1493 | - array( |
|
1494 | - 'char' => $lf, |
|
1495 | - 'type' => ConvertHelper_EOL::TYPE_LF, |
|
1496 | - 'description' => t('Line feed'), |
|
1497 | - ), |
|
1498 | - array( |
|
1499 | - 'char' => $cr, |
|
1500 | - 'type' => ConvertHelper_EOL::TYPE_CR, |
|
1501 | - 'description' => t('Carriage Return'), |
|
1502 | - ), |
|
1482 | + self::$eolChars = array( |
|
1483 | + array( |
|
1484 | + 'char' => $cr.$lf, |
|
1485 | + 'type' => ConvertHelper_EOL::TYPE_CRLF, |
|
1486 | + 'description' => t('Carriage return followed by a line feed'), |
|
1487 | + ), |
|
1488 | + array( |
|
1489 | + 'char' => $lf.$cr, |
|
1490 | + 'type' => ConvertHelper_EOL::TYPE_LFCR, |
|
1491 | + 'description' => t('Line feed followed by a carriage return'), |
|
1492 | + ), |
|
1493 | + array( |
|
1494 | + 'char' => $lf, |
|
1495 | + 'type' => ConvertHelper_EOL::TYPE_LF, |
|
1496 | + 'description' => t('Line feed'), |
|
1497 | + ), |
|
1498 | + array( |
|
1499 | + 'char' => $cr, |
|
1500 | + 'type' => ConvertHelper_EOL::TYPE_CR, |
|
1501 | + 'description' => t('Carriage Return'), |
|
1502 | + ), |
|
1503 | 1503 | ); |
1504 | 1504 | } |
1505 | 1505 | |
@@ -1527,13 +1527,13 @@ discard block |
||
1527 | 1527 | ); |
1528 | 1528 | } |
1529 | 1529 | |
1530 | - /** |
|
1531 | - * Removes the specified keys from the target array, |
|
1532 | - * if they exist. |
|
1533 | - * |
|
1534 | - * @param array $array |
|
1535 | - * @param array $keys |
|
1536 | - */ |
|
1530 | + /** |
|
1531 | + * Removes the specified keys from the target array, |
|
1532 | + * if they exist. |
|
1533 | + * |
|
1534 | + * @param array $array |
|
1535 | + * @param array $keys |
|
1536 | + */ |
|
1537 | 1537 | public static function arrayRemoveKeys(array &$array, array $keys) : void |
1538 | 1538 | { |
1539 | 1539 | foreach($keys as $key) |
@@ -1544,13 +1544,13 @@ discard block |
||
1544 | 1544 | } |
1545 | 1545 | } |
1546 | 1546 | |
1547 | - /** |
|
1548 | - * Checks if the specified variable is an integer or a string containing an integer. |
|
1549 | - * Accepts both positive and negative integers. |
|
1550 | - * |
|
1551 | - * @param mixed $value |
|
1552 | - * @return bool |
|
1553 | - */ |
|
1547 | + /** |
|
1548 | + * Checks if the specified variable is an integer or a string containing an integer. |
|
1549 | + * Accepts both positive and negative integers. |
|
1550 | + * |
|
1551 | + * @param mixed $value |
|
1552 | + * @return bool |
|
1553 | + */ |
|
1554 | 1554 | public static function isInteger($value) : bool |
1555 | 1555 | { |
1556 | 1556 | if(is_int($value)) { |
@@ -1570,15 +1570,15 @@ discard block |
||
1570 | 1570 | return false; |
1571 | 1571 | } |
1572 | 1572 | |
1573 | - /** |
|
1574 | - * Converts an amount of seconds to a DateInterval object. |
|
1575 | - * |
|
1576 | - * @param int $seconds |
|
1577 | - * @return \DateInterval |
|
1578 | - * @throws ConvertHelper_Exception If the date interval cannot be created. |
|
1579 | - * |
|
1580 | - * @see ConvertHelper::ERROR_CANNOT_GET_DATE_DIFF |
|
1581 | - */ |
|
1573 | + /** |
|
1574 | + * Converts an amount of seconds to a DateInterval object. |
|
1575 | + * |
|
1576 | + * @param int $seconds |
|
1577 | + * @return \DateInterval |
|
1578 | + * @throws ConvertHelper_Exception If the date interval cannot be created. |
|
1579 | + * |
|
1580 | + * @see ConvertHelper::ERROR_CANNOT_GET_DATE_DIFF |
|
1581 | + */ |
|
1582 | 1582 | public static function seconds2interval(int $seconds) : \DateInterval |
1583 | 1583 | { |
1584 | 1584 | // The DateInterval::format() method does not recalculate carry |