1 | <?php |
||
11 | final class Strings |
||
12 | { |
||
13 | /** |
||
14 | * Replaces the format items in a specified string with the string representation of n specified objects. |
||
15 | * |
||
16 | * @param string $format A composit format string |
||
17 | * @param mixed $arguments Variable number of items to format. |
||
18 | * |
||
19 | * @return string Returns a copy of format in which the format items have been |
||
20 | * replaced by the string representations of arg0, arg1,... argN. |
||
21 | * |
||
22 | * @throws \InvalidArgumentException Thrown if $format is not a string |
||
23 | * @throws \InvalidArgumentException Thrown if all arguments are not castable as strings or |
||
24 | * if less than two arguments are given |
||
25 | */ |
||
26 | public static function format(string $format, string ...$arguments) : string |
||
48 | |||
49 | /** |
||
50 | * Checks if $string ends with $suffix and puts the rest of the $string in $nonSuffix. |
||
51 | * |
||
52 | * @param string $string The string to check |
||
53 | * @param string $suffix The suffix to check for |
||
54 | * @param mixed &$nonSuffix This is the part of the string that is not the suffix. |
||
55 | * |
||
56 | * @return bool whether the $string ended with $suffix or not. |
||
57 | * |
||
58 | * @throws \InvalidArgumentException if $string is not a string |
||
59 | * @throws \InvalidArgumentException if $suffix is not a string |
||
60 | */ |
||
61 | public static function endsWith(string $string, string $suffix, &$nonSuffix = null) : bool |
||
89 | |||
90 | /** |
||
91 | * Truncates the string to the given length, with an ellipsis at the end. |
||
92 | * |
||
93 | * @param string $string The string to shorten. |
||
94 | * @param int $maxLength The length to truncate the string to. The result will not be longer than this, but may be |
||
95 | * shorter. |
||
96 | * @param string $suffix The string to append when truncating. Typically this will be an ellipsis. |
||
97 | * |
||
98 | * @return string The truncated string with the ellipsis included if truncation occured. |
||
99 | * |
||
100 | * @throws \InvalidArgumentException if $string is not a string |
||
101 | * @throws \InvalidArgumentException if $maxLength is not an integer |
||
102 | * @throws \InvalidArgumentException if $maxLength is negative |
||
103 | * @throws \InvalidArgumentException if $suffix is not a string |
||
104 | */ |
||
105 | public static function ellipsize(string $string, int $maxLength, string $suffix = '...') : string |
||
136 | |||
137 | /** |
||
138 | * Uppercases words using custom word delimiters. |
||
139 | * |
||
140 | * This is more flexible than normal php ucwords because that only treats space as a word delimiter. |
||
141 | * |
||
142 | * Here is an example: |
||
143 | * <code> |
||
144 | * <?php |
||
145 | * $string = 'break-down o\'boy up_town you+me here now,this:place'; |
||
146 | * |
||
147 | * echo String::ucwords($string); |
||
148 | * // Break-Down O\'Boy Up_Town You+Me Here Now,This:Place |
||
149 | * |
||
150 | * echo String::ucwords($string, '- '); |
||
151 | * // Break-Down O\'boy Up_town You+me Here Now,this:place |
||
152 | * ?> |
||
153 | * </code> |
||
154 | * |
||
155 | * @param string $string The string to titleize. |
||
156 | * @param string $delimiters The characters to treat as word delimiters. |
||
157 | * |
||
158 | * @return string The titleized string. |
||
159 | * |
||
160 | * @throws \InvalidArgumentException if $string is not a string |
||
161 | * @throws \InvalidArgumentException if $delimiters is not a string |
||
162 | */ |
||
163 | public static function ucwords(string $string, string $delimiters = "-_+' \n\t\r\0\x0B:/,.") : string |
||
185 | } |
||
186 |