1 | <?php |
||
22 | class StringHelper extends BaseStringHelper |
||
23 | { |
||
24 | /** |
||
25 | * TypeCast a string to its specific types. |
||
26 | * |
||
27 | * Arrays will passed to to the {{luya\helpers\ArrayHelper::typeCast()}} class. |
||
28 | * |
||
29 | * @param mixed $string The input string to type cast. Arrays will be passted to {{luya\helpers\ArrayHelper::typeCast()}}. |
||
30 | * @return mixed The new type casted value, if the input is an array the output is the typecasted array. |
||
31 | */ |
||
32 | public static function typeCast($string) |
||
42 | |||
43 | /** |
||
44 | * Checke whether a strings starts with the wildcard symbole and compares the string before the wild card symbol * |
||
45 | * with the string provided, if there is NO wildcard symbold it always return false. |
||
46 | * |
||
47 | * |
||
48 | * @param string $string The string which should be checked with $with comperator |
||
49 | * @param string $with The with string which must end with the wildcard symbol * e.g. `foo*` would match string `foobar`. |
||
50 | * @param boolean $caseSensitive Whether to compare the starts with string as case sensitive or not, defaults to true. |
||
51 | * @return boolean Whether the string starts with the wildcard marked string or not, if no wildcard symbol is contained. |
||
52 | * in the $with it always returns false. |
||
53 | */ |
||
54 | public static function startsWithWildcard($string, $with, $caseSensitive = true) |
||
62 | |||
63 | /** |
||
64 | * TypeCast a numeric value to float or integer. |
||
65 | * |
||
66 | * If the given value is not a numeric or float value it will be returned as it is. In order to find out whether its float |
||
67 | * or not use {{luya\helpers\StringHelper::isFloat()}}. |
||
68 | * |
||
69 | * @param mixed $value The given value to parse. |
||
70 | * @return mixed Returns the original value if not numeric or integer, float casted value. |
||
71 | */ |
||
72 | public static function typeCastNumeric($value) |
||
84 | |||
85 | /** |
||
86 | * Checks whether a string is a float value. |
||
87 | * |
||
88 | * Compared to `is_float` function of php, it only ensures whether the input variable is type float. |
||
89 | * |
||
90 | * @param mixed $value The value to check whether its float or not. |
||
91 | * @return boolean Whether its a float value or not. |
||
92 | */ |
||
93 | public static function isFloat($value) |
||
101 | |||
102 | /** |
||
103 | * Replace only the first occurance found inside the string. |
||
104 | * |
||
105 | * The replace first method is *case sensitive*. |
||
106 | * |
||
107 | * ```php |
||
108 | * StringHelper::replaceFirst('abc', '123', 'abc abc abc'); // returns "123 abc abc" |
||
109 | * ``` |
||
110 | * |
||
111 | * @param string $search Search string to look for. |
||
112 | * @param string $replace Replacement value for the first found occurrence. |
||
113 | * @param string $subject The string you want to look up to replace the first element. |
||
114 | * @return mixed Replaced string |
||
115 | */ |
||
116 | public static function replaceFirst($search, $replace, $subject) |
||
120 | |||
121 | /** |
||
122 | * Check whether a char or word exists in a string or not. |
||
123 | * |
||
124 | * This method is case sensitive. The need can be an array with multiple chars or words who |
||
125 | * are going to look up in the haystack string. |
||
126 | * |
||
127 | * If an array of needle words is provided the $strict parameter defines whether all need keys must be found |
||
128 | * in the string to get the `true` response or if just one of the keys are found the response is already `true`. |
||
129 | * |
||
130 | * @param string|array $needle The char or word to find in the $haystack. Can be an array to multi find words or char in the string. |
||
131 | * @param string $haystack The haystack where the $needle string should be looked up. |
||
132 | * @param boolean $strict If an array of needles is provided the $strict parameter defines whether all keys must be found ($strict = true) or just one result must be found ($strict = false). |
||
133 | * @return boolean If an array of values is provided the response may change depending on $findAll. |
||
134 | */ |
||
135 | public static function contains($needle, $haystack, $strict = false) |
||
155 | |||
156 | /** |
||
157 | * Minify html by removing spaces, tabs. |
||
158 | * |
||
159 | * @param string $content |
||
160 | * @return mixed |
||
161 | * @since 1.0.7 |
||
162 | */ |
||
163 | public static function minify($content) |
||
167 | } |
||
168 |