Total Complexity | 73 |
Total Lines | 719 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like Str often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Str, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
5 | class Str |
||
6 | { |
||
7 | |||
8 | /** |
||
9 | * The cache of snake-cased words. |
||
10 | * |
||
11 | * @var array |
||
12 | */ |
||
13 | protected static $snakeCache = []; |
||
14 | |||
15 | /** |
||
16 | * The cache of camel-cased words. |
||
17 | * |
||
18 | * @var array |
||
19 | */ |
||
20 | protected static $camelCache = []; |
||
21 | |||
22 | /** |
||
23 | * The cache of studly-cased words. |
||
24 | * |
||
25 | * @var array |
||
26 | */ |
||
27 | protected static $studlyCache = []; |
||
28 | |||
29 | /** |
||
30 | * Return the remainder of a string after a given value. |
||
31 | * |
||
32 | * @param string $subject |
||
33 | * @param string $search |
||
34 | * @return string |
||
35 | */ |
||
36 | public static function after($subject, $search) |
||
37 | { |
||
38 | return $search === '' ? $subject : array_reverse(explode($search, $subject, 2))[0]; |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * Transliterate a UTF-8 value to ASCII. |
||
43 | * |
||
44 | * @param string $value |
||
45 | * @param string $language |
||
46 | * @return string |
||
47 | */ |
||
48 | public static function ascii($value, $language = 'en') |
||
49 | { |
||
50 | $languageSpecific = static::languageSpecificCharsArray($language); |
||
51 | |||
52 | if (! is_null($languageSpecific)) { |
||
53 | $value = str_replace($languageSpecific[0], $languageSpecific[1], $value); |
||
54 | } |
||
55 | |||
56 | foreach (static::charsArray() as $key => $val) { |
||
57 | $value = str_replace($val, $key, $value); |
||
58 | } |
||
59 | |||
60 | return preg_replace('/[^\x20-\x7E]/u', '', $value); |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * Get the portion of a string before a given value. |
||
65 | * |
||
66 | * @param string $subject |
||
67 | * @param string $search |
||
68 | * @return string |
||
69 | */ |
||
70 | public static function before($subject, $search) |
||
71 | { |
||
72 | return $search === '' ? $subject : explode($search, $subject)[0]; |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * Convert a value to camel case. |
||
77 | * |
||
78 | * @param string $value |
||
79 | * @return string |
||
80 | */ |
||
81 | public static function camel($value) |
||
82 | { |
||
83 | if (isset(static::$camelCache[$value])) { |
||
84 | return static::$camelCache[$value]; |
||
85 | } |
||
86 | |||
87 | return static::$camelCache[$value] = lcfirst(static::studly($value)); |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * Determine if a given string contains a given substring. |
||
92 | * |
||
93 | * @param string $haystack |
||
94 | * @param string|array $needles |
||
95 | * @return bool |
||
96 | */ |
||
97 | public static function contains($haystack, $needles) |
||
98 | { |
||
99 | foreach ((array) $needles as $needle) { |
||
100 | if ($needle !== '' && mb_strpos($haystack, $needle) !== false) { |
||
101 | return true; |
||
102 | } |
||
103 | } |
||
104 | |||
105 | return false; |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * Determine if a given string ends with a given substring. |
||
110 | * |
||
111 | * @param string $haystack |
||
112 | * @param string|array $needles |
||
113 | * @return bool |
||
114 | */ |
||
115 | public static function endsWith($haystack, $needles) |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * Cap a string with a single instance of a given value. |
||
128 | * |
||
129 | * @param string $value |
||
130 | * @param string $cap |
||
131 | * @return string |
||
132 | */ |
||
133 | public static function finish($value, $cap) |
||
134 | { |
||
135 | $quoted = preg_quote($cap, '/'); |
||
136 | |||
137 | return preg_replace('/(?:'.$quoted.')+$/u', '', $value).$cap; |
||
138 | } |
||
139 | |||
140 | /** |
||
141 | * Determine if a given string matches a given pattern. |
||
142 | * |
||
143 | * @param string|array $pattern |
||
144 | * @param string $value |
||
145 | * @return bool |
||
146 | */ |
||
147 | public static function is($pattern, $value) |
||
148 | { |
||
149 | $patterns = is_array($pattern) ? $pattern : (array) $pattern; |
||
150 | |||
151 | if (empty($patterns)) { |
||
152 | return false; |
||
153 | } |
||
154 | |||
155 | foreach ($patterns as $pattern) { |
||
|
|||
156 | // If the given value is an exact match we can of course return true right |
||
157 | // from the beginning. Otherwise, we will translate asterisks and do an |
||
158 | // actual pattern match against the two strings to see if they match. |
||
159 | if ($pattern == $value) { |
||
160 | return true; |
||
161 | } |
||
162 | |||
163 | $pattern = preg_quote($pattern, '#'); |
||
164 | |||
165 | // Asterisks are translated into zero-or-more regular expression wildcards |
||
166 | // to make it convenient to check if the strings starts with the given |
||
167 | // pattern such as "library/*", making any string check convenient. |
||
168 | $pattern = str_replace('\*', '.*', $pattern); |
||
169 | |||
170 | if (preg_match('#^'.$pattern.'\z#u', $value) === 1) { |
||
171 | return true; |
||
172 | } |
||
173 | } |
||
174 | |||
175 | return false; |
||
176 | } |
||
177 | |||
178 | /** |
||
179 | * Convert a string to kebab case. |
||
180 | * |
||
181 | * @param string $value |
||
182 | * @return string |
||
183 | */ |
||
184 | public static function kebab($value) |
||
185 | { |
||
186 | return static::snake($value, '-'); |
||
187 | } |
||
188 | |||
189 | /** |
||
190 | * Return the length of the given string. |
||
191 | * |
||
192 | * @param string $value |
||
193 | * @param string $encoding |
||
194 | * @return int |
||
195 | */ |
||
196 | public static function length($value, $encoding = null) |
||
197 | { |
||
198 | if ($encoding) { |
||
199 | return mb_strlen($value, $encoding); |
||
200 | } |
||
201 | |||
202 | return mb_strlen($value); |
||
203 | } |
||
204 | |||
205 | /** |
||
206 | * Limit the number of characters in a string. |
||
207 | * |
||
208 | * @param string $value |
||
209 | * @param int $limit |
||
210 | * @param string $end |
||
211 | * @return string |
||
212 | */ |
||
213 | public static function limit($value, $limit = 100, $end = '...') |
||
214 | { |
||
215 | if (mb_strwidth($value, 'UTF-8') <= $limit) { |
||
216 | return $value; |
||
217 | } |
||
218 | |||
219 | return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')).$end; |
||
220 | } |
||
221 | |||
222 | /** |
||
223 | * Convert the given string to lower-case. |
||
224 | * |
||
225 | * @param string $value |
||
226 | * @return string |
||
227 | */ |
||
228 | public static function lower($value) |
||
231 | } |
||
232 | |||
233 | /** |
||
234 | * Convert the given string to lower-case. |
||
235 | * |
||
236 | * @param string $value |
||
237 | * @param string $crop |
||
238 | * @param string $case |
||
239 | * @return string |
||
240 | */ |
||
241 | public static function crop($value,$crop,$case='lower') |
||
242 | { |
||
243 | return static::$case(str_replace($crop,'',$value)); |
||
244 | } |
||
245 | |||
246 | /** |
||
247 | * Limit the number of words in a string. |
||
248 | * |
||
249 | * @param string $value |
||
250 | * @param int $words |
||
251 | * @param string $end |
||
252 | * @return string |
||
253 | */ |
||
254 | public static function words($value, $words = 100, $end = '...') |
||
255 | { |
||
256 | preg_match('/^\s*+(?:\S++\s*+){1,'.$words.'}/u', $value, $matches); |
||
257 | |||
258 | if (! isset($matches[0]) || static::length($value) === static::length($matches[0])) { |
||
259 | return $value; |
||
260 | } |
||
261 | |||
262 | return rtrim($matches[0]).$end; |
||
263 | } |
||
264 | |||
265 | /** |
||
266 | * Parse a Class@method style callback into class and method. |
||
267 | * |
||
268 | * @param string $callback |
||
269 | * @param string|null $default |
||
270 | * @return array |
||
271 | */ |
||
272 | public static function parseCallback($callback, $default = null) |
||
273 | { |
||
274 | return static::contains($callback, '@') ? explode('@', $callback, 2) : [$callback, $default]; |
||
275 | } |
||
276 | |||
277 | |||
278 | /** |
||
279 | * @param int $length |
||
280 | * @return string |
||
281 | * @throws \Exception |
||
282 | */ |
||
283 | public static function random($length = 16) |
||
296 | } |
||
297 | |||
298 | /** |
||
299 | * replace word array |
||
300 | * |
||
301 | * @param array $word |
||
302 | * @param $replace |
||
303 | * @param $subject |
||
304 | * @return string |
||
305 | */ |
||
306 | public static function replaceWordArray($word, $replace, $subject) |
||
307 | { |
||
308 | if(is_array($word)){ |
||
309 | |||
310 | foreach ($word as $value) { |
||
311 | $subject = str_replace($value,$replace,$subject); |
||
312 | } |
||
313 | } |
||
314 | |||
315 | return $subject; |
||
316 | } |
||
317 | |||
318 | /** |
||
319 | * Replace a given value in the string sequentially with an array. |
||
320 | * |
||
321 | * @param string $search |
||
322 | * @param array $replace |
||
323 | * @param string $subject |
||
324 | * @return string |
||
325 | */ |
||
326 | public static function replaceArray($search, array $replace, $subject) |
||
327 | { |
||
328 | foreach ($replace as $value) { |
||
329 | $subject = static::replaceFirst($search, $value, $subject); |
||
330 | } |
||
331 | |||
332 | return $subject; |
||
333 | } |
||
334 | |||
335 | /** |
||
336 | * Replace the first occurrence of a given value in the string. |
||
337 | * |
||
338 | * @param string $search |
||
339 | * @param string $replace |
||
340 | * @param string $subject |
||
341 | * @return string |
||
342 | */ |
||
343 | public static function replaceFirst($search, $replace, $subject) |
||
344 | { |
||
345 | if ($search == '') { |
||
346 | return $subject; |
||
347 | } |
||
348 | |||
349 | $position = mb_strpos($subject, $search); |
||
350 | |||
351 | if ($position !== false) { |
||
352 | return mb_substr($subject, 0, $position).$replace.mb_substr($subject, $position + mb_strlen($search)); |
||
353 | } |
||
354 | |||
355 | return $subject; |
||
356 | } |
||
357 | |||
358 | /** |
||
359 | * Replace the last occurrence of a given value in the string. |
||
360 | * |
||
361 | * @param string $search |
||
362 | * @param string $replace |
||
363 | * @param string $subject |
||
364 | * @return string |
||
365 | */ |
||
366 | public static function replaceLast($search, $replace, $subject) |
||
375 | } |
||
376 | |||
377 | /** |
||
378 | * Begin a string with a single instance of a given value. |
||
379 | * |
||
380 | * @param string $value |
||
381 | * @param string $prefix |
||
382 | * @return string |
||
383 | */ |
||
384 | public static function start($value, $prefix) |
||
385 | { |
||
386 | $quoted = preg_quote($prefix, '/'); |
||
387 | |||
388 | return $prefix.preg_replace('/^(?:'.$quoted.')+/u', '', $value); |
||
389 | } |
||
390 | |||
391 | /** |
||
392 | * Convert the given string to upper-case. |
||
393 | * |
||
394 | * @param string $value |
||
395 | * @return string |
||
396 | */ |
||
397 | public static function upper($value) |
||
398 | { |
||
399 | return mb_strtoupper($value, 'UTF-8'); |
||
400 | } |
||
401 | |||
402 | /** |
||
403 | * Convert the given string to title case. |
||
404 | * |
||
405 | * @param string $value |
||
406 | * @return string |
||
407 | */ |
||
408 | public static function title($value) |
||
409 | { |
||
410 | return mb_convert_case($value, MB_CASE_TITLE, 'UTF-8'); |
||
411 | } |
||
412 | |||
413 | /** |
||
414 | * Generate a URL friendly "slug" from a given string. |
||
415 | * |
||
416 | * @param string $title |
||
417 | * @param string $separator |
||
418 | * @param string $language |
||
419 | * @return string |
||
420 | */ |
||
421 | public static function slug($title, $separator = '-', $language = 'en') |
||
422 | { |
||
423 | $title = static::ascii($title, $language); |
||
424 | |||
425 | // Convert all dashes/underscores into separator |
||
426 | $flip = $separator == '-' ? '_' : '-'; |
||
427 | |||
428 | $title = preg_replace('!['.preg_quote($flip).']+!u', $separator, $title); |
||
429 | |||
430 | // Replace @ with the word 'at' |
||
431 | $title = str_replace('@', $separator.'at'.$separator, $title); |
||
432 | |||
433 | // Remove all characters that are not the separator, letters, numbers, or whitespace. |
||
434 | $title = preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', mb_strtolower($title)); |
||
435 | |||
436 | // Replace all separator characters and whitespace by a single separator |
||
437 | $title = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $title); |
||
438 | |||
439 | return trim($title, $separator); |
||
440 | } |
||
441 | |||
442 | /** |
||
443 | * Convert a string to snake case. |
||
444 | * |
||
445 | * @param string $value |
||
446 | * @param string $delimiter |
||
447 | * @return string |
||
448 | */ |
||
449 | public static function snake($value, $delimiter = '_') |
||
450 | { |
||
451 | $key = $value; |
||
452 | |||
453 | if (isset(static::$snakeCache[$key][$delimiter])) { |
||
454 | return static::$snakeCache[$key][$delimiter]; |
||
455 | } |
||
456 | |||
457 | if (! ctype_lower($value)) { |
||
458 | $value = preg_replace('/\s+/u', '', ucwords($value)); |
||
459 | |||
460 | $value = static::lower(preg_replace('/(.)(?=[A-Z])/u', '$1'.$delimiter, $value)); |
||
461 | } |
||
462 | |||
463 | return static::$snakeCache[$key][$delimiter] = $value; |
||
464 | } |
||
465 | |||
466 | /** |
||
467 | * Determine if a given string starts with a given substring. |
||
468 | * |
||
469 | * @param string $haystack |
||
470 | * @param string|array $needles |
||
471 | * @return bool |
||
472 | */ |
||
473 | public static function startsWith($haystack, $needles) |
||
474 | { |
||
475 | foreach ((array) $needles as $needle) { |
||
476 | if ($needle !== '' && mb_substr($haystack, 0, mb_strlen($needle)) === (string) $needle) { |
||
477 | return true; |
||
478 | } |
||
479 | } |
||
480 | |||
481 | return false; |
||
482 | } |
||
483 | |||
484 | /** |
||
485 | * Convert a value to studly caps case. |
||
486 | * |
||
487 | * @param string $value |
||
488 | * @return string |
||
489 | */ |
||
490 | public static function studly($value) |
||
501 | } |
||
502 | |||
503 | /** |
||
504 | * Returns the portion of string specified by the start and length parameters. |
||
505 | * |
||
506 | * @param string $string |
||
507 | * @param int $start |
||
508 | * @param int|null $length |
||
509 | * @return string |
||
510 | */ |
||
511 | public static function substr($string, $start, $length = null) |
||
512 | { |
||
513 | return mb_substr($string, $start, $length, 'UTF-8'); |
||
514 | } |
||
515 | |||
516 | /** |
||
517 | * Make a string's first character uppercase. |
||
518 | * |
||
519 | * @param string $string |
||
520 | * @return string |
||
521 | */ |
||
522 | public static function ucfirst($string) |
||
523 | { |
||
524 | return static::upper(static::substr($string, 0, 1)).static::substr($string, 1); |
||
525 | } |
||
526 | |||
527 | /** |
||
528 | * Returns the replacements for the ascii method. |
||
529 | * |
||
530 | * Note: Adapted from Stringy\Stringy. |
||
531 | * |
||
532 | * @see https://github.com/danielstjules/Stringy/blob/3.1.0/LICENSE.txt |
||
533 | * |
||
534 | * @return array |
||
535 | */ |
||
536 | protected static function charsArray() |
||
537 | { |
||
538 | static $charsArray; |
||
539 | |||
540 | if (isset($charsArray)) { |
||
541 | return $charsArray; |
||
542 | } |
||
543 | |||
544 | return $charsArray = [ |
||
545 | '0' => ['°', '₀', '۰', '0'], |
||
546 | '1' => ['¹', '₁', '۱', '1'], |
||
547 | '2' => ['²', '₂', '۲', '2'], |
||
548 | '3' => ['³', '₃', '۳', '3'], |
||
549 | '4' => ['⁴', '₄', '۴', '٤', '4'], |
||
550 | '5' => ['⁵', '₅', '۵', '٥', '5'], |
||
551 | '6' => ['⁶', '₆', '۶', '٦', '6'], |
||
552 | '7' => ['⁷', '₇', '۷', '7'], |
||
553 | '8' => ['⁸', '₈', '۸', '8'], |
||
554 | '9' => ['⁹', '₉', '۹', '9'], |
||
555 | 'a' => ['à', 'á', 'ả', 'ã', 'ạ', 'ă', 'ắ', 'ằ', 'ẳ', 'ẵ', 'ặ', 'â', 'ấ', 'ầ', 'ẩ', 'ẫ', 'ậ', 'ā', 'ą', 'å', 'α', 'ά', 'ἀ', 'ἁ', 'ἂ', 'ἃ', 'ἄ', 'ἅ', 'ἆ', 'ἇ', 'ᾀ', 'ᾁ', 'ᾂ', 'ᾃ', 'ᾄ', 'ᾅ', 'ᾆ', 'ᾇ', 'ὰ', 'ά', 'ᾰ', 'ᾱ', 'ᾲ', 'ᾳ', 'ᾴ', 'ᾶ', 'ᾷ', 'а', 'أ', 'အ', 'ာ', 'ါ', 'ǻ', 'ǎ', 'ª', 'ა', 'अ', 'ا', 'a', 'ä'], |
||
556 | 'b' => ['б', 'β', 'ب', 'ဗ', 'ბ', 'b'], |
||
557 | 'c' => ['ç', 'ć', 'č', 'ĉ', 'ċ', 'c'], |
||
558 | 'd' => ['ď', 'ð', 'đ', 'ƌ', 'ȡ', 'ɖ', 'ɗ', 'ᵭ', 'ᶁ', 'ᶑ', 'д', 'δ', 'د', 'ض', 'ဍ', 'ဒ', 'დ', 'd'], |
||
559 | 'e' => ['é', 'è', 'ẻ', 'ẽ', 'ẹ', 'ê', 'ế', 'ề', 'ể', 'ễ', 'ệ', 'ë', 'ē', 'ę', 'ě', 'ĕ', 'ė', 'ε', 'έ', 'ἐ', 'ἑ', 'ἒ', 'ἓ', 'ἔ', 'ἕ', 'ὲ', 'έ', 'е', 'ё', 'э', 'є', 'ə', 'ဧ', 'ေ', 'ဲ', 'ე', 'ए', 'إ', 'ئ', 'e'], |
||
560 | 'f' => ['ф', 'φ', 'ف', 'ƒ', 'ფ', 'f'], |
||
561 | 'g' => ['ĝ', 'ğ', 'ġ', 'ģ', 'г', 'ґ', 'γ', 'ဂ', 'გ', 'گ', 'g'], |
||
562 | 'h' => ['ĥ', 'ħ', 'η', 'ή', 'ح', 'ه', 'ဟ', 'ှ', 'ჰ', 'h'], |
||
563 | 'i' => ['í', 'ì', 'ỉ', 'ĩ', 'ị', 'î', 'ï', 'ī', 'ĭ', 'į', 'ı', 'ι', 'ί', 'ϊ', 'ΐ', 'ἰ', 'ἱ', 'ἲ', 'ἳ', 'ἴ', 'ἵ', 'ἶ', 'ἷ', 'ὶ', 'ί', 'ῐ', 'ῑ', 'ῒ', 'ΐ', 'ῖ', 'ῗ', 'і', 'ї', 'и', 'ဣ', 'ိ', 'ီ', 'ည်', 'ǐ', 'ი', 'इ', 'ی', 'i'], |
||
564 | 'j' => ['ĵ', 'ј', 'Ј', 'ჯ', 'ج', 'j'], |
||
565 | 'k' => ['ķ', 'ĸ', 'к', 'κ', 'Ķ', 'ق', 'ك', 'က', 'კ', 'ქ', 'ک', 'k'], |
||
566 | 'l' => ['ł', 'ľ', 'ĺ', 'ļ', 'ŀ', 'л', 'λ', 'ل', 'လ', 'ლ', 'l'], |
||
567 | 'm' => ['м', 'μ', 'م', 'မ', 'მ', 'm'], |
||
568 | 'n' => ['ñ', 'ń', 'ň', 'ņ', 'ʼn', 'ŋ', 'ν', 'н', 'ن', 'န', 'ნ', 'n'], |
||
569 | 'o' => ['ó', 'ò', 'ỏ', 'õ', 'ọ', 'ô', 'ố', 'ồ', 'ổ', 'ỗ', 'ộ', 'ơ', 'ớ', 'ờ', 'ở', 'ỡ', 'ợ', 'ø', 'ō', 'ő', 'ŏ', 'ο', 'ὀ', 'ὁ', 'ὂ', 'ὃ', 'ὄ', 'ὅ', 'ὸ', 'ό', 'о', 'و', 'θ', 'ို', 'ǒ', 'ǿ', 'º', 'ო', 'ओ', 'o', 'ö'], |
||
570 | 'p' => ['п', 'π', 'ပ', 'პ', 'پ', 'p'], |
||
571 | 'q' => ['ყ', 'q'], |
||
572 | 'r' => ['ŕ', 'ř', 'ŗ', 'р', 'ρ', 'ر', 'რ', 'r'], |
||
573 | 's' => ['ś', 'š', 'ş', 'с', 'σ', 'ș', 'ς', 'س', 'ص', 'စ', 'ſ', 'ს', 's'], |
||
574 | 't' => ['ť', 'ţ', 'т', 'τ', 'ț', 'ت', 'ط', 'ဋ', 'တ', 'ŧ', 'თ', 'ტ', 't'], |
||
575 | 'u' => ['ú', 'ù', 'ủ', 'ũ', 'ụ', 'ư', 'ứ', 'ừ', 'ử', 'ữ', 'ự', 'û', 'ū', 'ů', 'ű', 'ŭ', 'ų', 'µ', 'у', 'ဉ', 'ု', 'ူ', 'ǔ', 'ǖ', 'ǘ', 'ǚ', 'ǜ', 'უ', 'उ', 'u', 'ў', 'ü'], |
||
576 | 'v' => ['в', 'ვ', 'ϐ', 'v'], |
||
577 | 'w' => ['ŵ', 'ω', 'ώ', 'ဝ', 'ွ', 'w'], |
||
578 | 'x' => ['χ', 'ξ', 'x'], |
||
579 | 'y' => ['ý', 'ỳ', 'ỷ', 'ỹ', 'ỵ', 'ÿ', 'ŷ', 'й', 'ы', 'υ', 'ϋ', 'ύ', 'ΰ', 'ي', 'ယ', 'y'], |
||
580 | 'z' => ['ź', 'ž', 'ż', 'з', 'ζ', 'ز', 'ဇ', 'ზ', 'z'], |
||
581 | 'aa' => ['ع', 'आ', 'آ'], |
||
582 | 'ae' => ['æ', 'ǽ'], |
||
583 | 'ai' => ['ऐ'], |
||
584 | 'ch' => ['ч', 'ჩ', 'ჭ', 'چ'], |
||
585 | 'dj' => ['ђ', 'đ'], |
||
586 | 'dz' => ['џ', 'ძ'], |
||
587 | 'ei' => ['ऍ'], |
||
588 | 'gh' => ['غ', 'ღ'], |
||
589 | 'ii' => ['ई'], |
||
590 | 'ij' => ['ij'], |
||
591 | 'kh' => ['х', 'خ', 'ხ'], |
||
592 | 'lj' => ['љ'], |
||
593 | 'nj' => ['њ'], |
||
594 | 'oe' => ['ö', 'œ', 'ؤ'], |
||
595 | 'oi' => ['ऑ'], |
||
596 | 'oii' => ['ऒ'], |
||
597 | 'ps' => ['ψ'], |
||
598 | 'sh' => ['ш', 'შ', 'ش'], |
||
599 | 'shch' => ['щ'], |
||
600 | 'ss' => ['ß'], |
||
601 | 'sx' => ['ŝ'], |
||
602 | 'th' => ['þ', 'ϑ', 'ث', 'ذ', 'ظ'], |
||
603 | 'ts' => ['ц', 'ც', 'წ'], |
||
604 | 'ue' => ['ü'], |
||
605 | 'uu' => ['ऊ'], |
||
606 | 'ya' => ['я'], |
||
607 | 'yu' => ['ю'], |
||
608 | 'zh' => ['ж', 'ჟ', 'ژ'], |
||
609 | '(c)' => ['©'], |
||
610 | 'A' => ['Á', 'À', 'Ả', 'Ã', 'Ạ', 'Ă', 'Ắ', 'Ằ', 'Ẳ', 'Ẵ', 'Ặ', 'Â', 'Ấ', 'Ầ', 'Ẩ', 'Ẫ', 'Ậ', 'Å', 'Ā', 'Ą', 'Α', 'Ά', 'Ἀ', 'Ἁ', 'Ἂ', 'Ἃ', 'Ἄ', 'Ἅ', 'Ἆ', 'Ἇ', 'ᾈ', 'ᾉ', 'ᾊ', 'ᾋ', 'ᾌ', 'ᾍ', 'ᾎ', 'ᾏ', 'Ᾰ', 'Ᾱ', 'Ὰ', 'Ά', 'ᾼ', 'А', 'Ǻ', 'Ǎ', 'A', 'Ä'], |
||
611 | 'B' => ['Б', 'Β', 'ब', 'B'], |
||
612 | 'C' => ['Ç', 'Ć', 'Č', 'Ĉ', 'Ċ', 'C'], |
||
613 | 'D' => ['Ď', 'Ð', 'Đ', 'Ɖ', 'Ɗ', 'Ƌ', 'ᴅ', 'ᴆ', 'Д', 'Δ', 'D'], |
||
614 | 'E' => ['É', 'È', 'Ẻ', 'Ẽ', 'Ẹ', 'Ê', 'Ế', 'Ề', 'Ể', 'Ễ', 'Ệ', 'Ë', 'Ē', 'Ę', 'Ě', 'Ĕ', 'Ė', 'Ε', 'Έ', 'Ἐ', 'Ἑ', 'Ἒ', 'Ἓ', 'Ἔ', 'Ἕ', 'Έ', 'Ὲ', 'Е', 'Ё', 'Э', 'Є', 'Ə', 'E'], |
||
615 | 'F' => ['Ф', 'Φ', 'F'], |
||
616 | 'G' => ['Ğ', 'Ġ', 'Ģ', 'Г', 'Ґ', 'Γ', 'G'], |
||
617 | 'H' => ['Η', 'Ή', 'Ħ', 'H'], |
||
618 | 'I' => ['Í', 'Ì', 'Ỉ', 'Ĩ', 'Ị', 'Î', 'Ï', 'Ī', 'Ĭ', 'Į', 'İ', 'Ι', 'Ί', 'Ϊ', 'Ἰ', 'Ἱ', 'Ἳ', 'Ἴ', 'Ἵ', 'Ἶ', 'Ἷ', 'Ῐ', 'Ῑ', 'Ὶ', 'Ί', 'И', 'І', 'Ї', 'Ǐ', 'ϒ', 'I'], |
||
619 | 'J' => ['J'], |
||
620 | 'K' => ['К', 'Κ', 'K'], |
||
621 | 'L' => ['Ĺ', 'Ł', 'Л', 'Λ', 'Ļ', 'Ľ', 'Ŀ', 'ल', 'L'], |
||
622 | 'M' => ['М', 'Μ', 'M'], |
||
623 | 'N' => ['Ń', 'Ñ', 'Ň', 'Ņ', 'Ŋ', 'Н', 'Ν', 'N'], |
||
624 | 'O' => ['Ó', 'Ò', 'Ỏ', 'Õ', 'Ọ', 'Ô', 'Ố', 'Ồ', 'Ổ', 'Ỗ', 'Ộ', 'Ơ', 'Ớ', 'Ờ', 'Ở', 'Ỡ', 'Ợ', 'Ø', 'Ō', 'Ő', 'Ŏ', 'Ο', 'Ό', 'Ὀ', 'Ὁ', 'Ὂ', 'Ὃ', 'Ὄ', 'Ὅ', 'Ὸ', 'Ό', 'О', 'Θ', 'Ө', 'Ǒ', 'Ǿ', 'O', 'Ö'], |
||
625 | 'P' => ['П', 'Π', 'P'], |
||
626 | 'Q' => ['Q'], |
||
627 | 'R' => ['Ř', 'Ŕ', 'Р', 'Ρ', 'Ŗ', 'R'], |
||
628 | 'S' => ['Ş', 'Ŝ', 'Ș', 'Š', 'Ś', 'С', 'Σ', 'S'], |
||
629 | 'T' => ['Ť', 'Ţ', 'Ŧ', 'Ț', 'Т', 'Τ', 'T'], |
||
630 | 'U' => ['Ú', 'Ù', 'Ủ', 'Ũ', 'Ụ', 'Ư', 'Ứ', 'Ừ', 'Ử', 'Ữ', 'Ự', 'Û', 'Ū', 'Ů', 'Ű', 'Ŭ', 'Ų', 'У', 'Ǔ', 'Ǖ', 'Ǘ', 'Ǚ', 'Ǜ', 'U', 'Ў', 'Ü'], |
||
631 | 'V' => ['В', 'V'], |
||
632 | 'W' => ['Ω', 'Ώ', 'Ŵ', 'W'], |
||
633 | 'X' => ['Χ', 'Ξ', 'X'], |
||
634 | 'Y' => ['Ý', 'Ỳ', 'Ỷ', 'Ỹ', 'Ỵ', 'Ÿ', 'Ῠ', 'Ῡ', 'Ὺ', 'Ύ', 'Ы', 'Й', 'Υ', 'Ϋ', 'Ŷ', 'Y'], |
||
635 | 'Z' => ['Ź', 'Ž', 'Ż', 'З', 'Ζ', 'Z'], |
||
636 | 'AE' => ['Æ', 'Ǽ'], |
||
637 | 'Ch' => ['Ч'], |
||
638 | 'Dj' => ['Ђ'], |
||
639 | 'Dz' => ['Џ'], |
||
640 | 'Gx' => ['Ĝ'], |
||
641 | 'Hx' => ['Ĥ'], |
||
642 | 'Ij' => ['IJ'], |
||
643 | 'Jx' => ['Ĵ'], |
||
644 | 'Kh' => ['Х'], |
||
645 | 'Lj' => ['Љ'], |
||
646 | 'Nj' => ['Њ'], |
||
647 | 'Oe' => ['Œ'], |
||
648 | 'Ps' => ['Ψ'], |
||
649 | 'Sh' => ['Ш'], |
||
650 | 'Shch' => ['Щ'], |
||
651 | 'Ss' => ['ẞ'], |
||
652 | 'Th' => ['Þ'], |
||
653 | 'Ts' => ['Ц'], |
||
654 | 'Ya' => ['Я'], |
||
655 | 'Yu' => ['Ю'], |
||
656 | 'Zh' => ['Ж'], |
||
657 | ' ' => ["\xC2\xA0", "\xE2\x80\x80", "\xE2\x80\x81", "\xE2\x80\x82", "\xE2\x80\x83", "\xE2\x80\x84", "\xE2\x80\x85", "\xE2\x80\x86", "\xE2\x80\x87", "\xE2\x80\x88", "\xE2\x80\x89", "\xE2\x80\x8A", "\xE2\x80\xAF", "\xE2\x81\x9F", "\xE3\x80\x80", "\xEF\xBE\xA0"], |
||
658 | ]; |
||
659 | } |
||
660 | |||
661 | /** |
||
662 | * Returns the language specific replacements for the ascii method. |
||
663 | * |
||
664 | * Note: Adapted from Stringy\Stringy. |
||
665 | * |
||
666 | * @see https://github.com/danielstjules/Stringy/blob/3.1.0/LICENSE.txt |
||
667 | * |
||
668 | * @param string $language |
||
669 | * @return array|null |
||
670 | */ |
||
671 | protected static function languageSpecificCharsArray($language) |
||
672 | { |
||
673 | static $languageSpecific; |
||
674 | |||
675 | if (! isset($languageSpecific)) { |
||
676 | $languageSpecific = [ |
||
677 | 'bg' => [ |
||
678 | ['х', 'Х', 'щ', 'Щ', 'ъ', 'Ъ', 'ь', 'Ь'], |
||
679 | ['h', 'H', 'sht', 'SHT', 'a', 'А', 'y', 'Y'], |
||
680 | ], |
||
681 | 'de' => [ |
||
682 | ['ä', 'ö', 'ü', 'Ä', 'Ö', 'Ü'], |
||
683 | ['ae', 'oe', 'ue', 'AE', 'OE', 'UE'], |
||
684 | ], |
||
685 | ]; |
||
686 | } |
||
687 | |||
688 | return $languageSpecific[$language] ?? null; |
||
689 | } |
||
690 | |||
691 | /** |
||
692 | * @param $data |
||
693 | * @return mixed |
||
694 | */ |
||
695 | public static function slashToBackSlash($data) |
||
698 | } |
||
699 | |||
700 | /** |
||
701 | * @param $string |
||
702 | * @param string $explode |
||
703 | * @return array |
||
704 | */ |
||
705 | public static function stringToArray($string,$explode=".") |
||
708 | } |
||
709 | |||
710 | /** |
||
711 | * @param null $removeCharacter |
||
712 | * @return null|string|string[] |
||
713 | */ |
||
714 | public static function removeCharacterFromUri($removeCharacter=null) |
||
724 | } |
||
725 | |||
726 | } |
||
727 | } |