1 | <?php |
||
15 | class StrHelper |
||
16 | { |
||
17 | /** |
||
18 | * Check if string contain $needle |
||
19 | * Old name: haveStr |
||
20 | * |
||
21 | * @param string $haystack |
||
22 | * @param string $needle |
||
23 | * @param bool $caseSensitivity |
||
24 | * @return bool |
||
25 | */ |
||
26 | public static function contain(string $haystack, string $needle, bool $caseSensitivity = true) : bool |
||
34 | |||
35 | /** |
||
36 | * Check if string start from $needle |
||
37 | * @param string $haystack |
||
38 | * @param string $needle |
||
39 | * @param bool $caseSensitivity |
||
40 | * @return bool |
||
41 | */ |
||
42 | public static function start(string $haystack, string $needle, bool $caseSensitivity = true) : bool |
||
51 | |||
52 | /** |
||
53 | * Check if string end by $needle |
||
54 | * @param string $haystack |
||
55 | * @param string $needle |
||
56 | * @param bool $caseSensitivity |
||
57 | * @return bool |
||
58 | */ |
||
59 | public static function end(string $haystack, string $needle, bool $caseSensitivity = true) : bool |
||
68 | |||
69 | /** |
||
70 | * SQL Like operator in PHP. |
||
71 | * Returns TRUE if match else FALSE. |
||
72 | * @param string $subject |
||
73 | * @param string $pattern |
||
74 | * @param bool $caseSensitivity |
||
75 | * @return bool |
||
76 | */ |
||
77 | public static function like(string $subject, string $pattern, bool $caseSensitivity = true) : bool |
||
86 | |||
87 | /** |
||
88 | * Remove prefix from string if string start from prefix |
||
89 | * @param string $str |
||
90 | * @param string $prefix |
||
91 | * @return string |
||
92 | */ |
||
93 | public static function removePrefix(string $str, string $prefix) : string |
||
102 | |||
103 | /** |
||
104 | * Find prefix if exist. If no - return default. |
||
105 | * Return array - first value is prefix, second == after prefix |
||
106 | * @param string $str |
||
107 | * @param array $prefixes |
||
108 | * @param string|null $default |
||
109 | * @return array |
||
110 | */ |
||
111 | public static function findPrefix(string $str, array $prefixes, ?string $default = null) : array |
||
121 | |||
122 | /** |
||
123 | * Convert string to int |
||
124 | * Can be used for short nicknames etc |
||
125 | * return null if too big number |
||
126 | * |
||
127 | * @param string $str |
||
128 | * @return int|null |
||
129 | */ |
||
130 | public static function str2int(string $str) : ?int { |
||
142 | |||
143 | /** |
||
144 | * Convert integer to string |
||
145 | * @see str2int |
||
146 | * |
||
147 | * @param int $i |
||
148 | * @return string |
||
149 | */ |
||
150 | public static function int2str(int $i) : string { |
||
153 | |||
154 | /** |
||
155 | * Transform string from camel case format to underscore |
||
156 | * @param string $key |
||
157 | * @return string |
||
158 | */ |
||
159 | public static function camelCase2underscore(string $key) : string { |
||
171 | |||
172 | /** |
||
173 | * Transform underscore format, to camel case |
||
174 | * @param string $key |
||
175 | * @return string |
||
176 | */ |
||
177 | public static function underscore2camelCase(string $key) : string { |
||
188 | |||
189 | /** |
||
190 | * Simple prettyfyer for keys |
||
191 | * Make readable names from key |
||
192 | * @param string $key |
||
193 | * @return string |
||
194 | */ |
||
195 | public static function key2Label(string $key) : string { |
||
202 | |||
203 | /** |
||
204 | * Parse doc comment string and get array of trimmed strings |
||
205 | * @param string $doc |
||
206 | * @return array |
||
207 | */ |
||
208 | public static function parseDocComment(string $doc) : array { |
||
222 | |||
223 | /** |
||
224 | * Make string from template |
||
225 | * @param string $template |
||
226 | * @param type $data |
||
227 | * @return string |
||
228 | */ |
||
229 | public static function templateToString(string $template, $data = []) : string { |
||
237 | |||
238 | /** |
||
239 | * Take data from string using template |
||
240 | * if not correct template - return null |
||
241 | * Dont support nested keys, return it at doted format |
||
242 | * |
||
243 | * @param string $template |
||
244 | * @param string $data |
||
245 | * @return array|null |
||
246 | */ |
||
247 | public static function templateFromString(string $template, string $data) : ?array { |
||
257 | |||
258 | /** |
||
259 | * Return list of keys at template |
||
260 | * @param string $template |
||
261 | * @return array |
||
262 | */ |
||
263 | public static function templateKeys(string $template): array { |
||
267 | |||
268 | /** |
||
269 | * Make pattern for parsing string |
||
270 | * @see templateFromString |
||
271 | * @param string $template |
||
272 | * @param array $keys |
||
273 | * @return string |
||
274 | */ |
||
275 | protected static function makeTemplatePattern(string $template, array $keys) : string { |
||
283 | } |
||
284 |