@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | |
12 | 12 | namespace Symfony\Polyfill\Intl\Grapheme; |
13 | 13 | |
14 | -\define('SYMFONY_GRAPHEME_CLUSTER_RX', \PCRE_VERSION >= '8.32' ? '\X' : Grapheme::GRAPHEME_CLUSTER_RX); |
|
14 | +\define( 'SYMFONY_GRAPHEME_CLUSTER_RX', \PCRE_VERSION >= '8.32' ? '\X' : Grapheme::GRAPHEME_CLUSTER_RX ); |
|
15 | 15 | |
16 | 16 | /** |
17 | 17 | * Partial intl implementation in pure PHP. |
@@ -38,54 +38,54 @@ discard block |
||
38 | 38 | public const GRAPHEME_CLUSTER_RX = '(?:\r\n|(?:[ -~\x{200C}\x{200D}]|[ᆨ-ᇹ]+|[ᄀ-ᅟ]*(?:[가개갸걔거게겨계고과괘괴교구궈궤귀규그긔기까깨꺄꺠꺼께껴꼐꼬꽈꽤꾀꾜꾸꿔꿰뀌뀨끄끠끼나내냐냬너네녀녜노놔놰뇌뇨누눠눼뉘뉴느늬니다대댜댸더데뎌뎨도돠돼되됴두둬뒈뒤듀드듸디따때땨떄떠떼뗘뗴또똬뙈뙤뚀뚜뚸뛔뛰뜌뜨띄띠라래랴럐러레려례로롸뢔뢰료루뤄뤠뤼류르릐리마매먀먜머메며몌모뫄뫠뫼묘무뭐뭬뮈뮤므믜미바배뱌뱨버베벼볘보봐봬뵈뵤부붜붸뷔뷰브븨비빠빼뺘뺴뻐뻬뼈뼤뽀뽜뽸뾔뾰뿌뿨쀄쀠쀼쁘쁴삐사새샤섀서세셔셰소솨쇄쇠쇼수숴쉐쉬슈스싀시싸쌔쌰썌써쎄쎠쎼쏘쏴쐐쐬쑈쑤쒀쒜쒸쓔쓰씌씨아애야얘어에여예오와왜외요우워웨위유으의이자재쟈쟤저제져졔조좌좨죄죠주줘줴쥐쥬즈즤지짜째쨔쨰쩌쩨쪄쪠쪼쫘쫴쬐쬬쭈쭤쮀쮜쮸쯔쯰찌차채챠챼처체쳐쳬초촤쵀최쵸추춰췌취츄츠츼치카캐캬컈커케켜켸코콰쾌쾨쿄쿠쿼퀘퀴큐크킈키타태탸턔터테텨톄토톼퇘퇴툐투퉈퉤튀튜트틔티파패퍄퍠퍼페펴폐포퐈퐤푀표푸풔풰퓌퓨프픠피하해햐햬허헤혀혜호화홰회효후훠훼휘휴흐희히]?[ᅠ-ᆢ]+|[가-힣])[ᆨ-ᇹ]*|[ᄀ-ᅟ]+|[^\p{Cc}\p{Cf}\p{Zl}\p{Zp}])[\p{Mn}\p{Me}\x{09BE}\x{09D7}\x{0B3E}\x{0B57}\x{0BBE}\x{0BD7}\x{0CC2}\x{0CD5}\x{0CD6}\x{0D3E}\x{0D57}\x{0DCF}\x{0DDF}\x{200C}\x{200D}\x{1D165}\x{1D16E}-\x{1D172}]*|[\p{Cc}\p{Cf}\p{Zl}\p{Zp}])'; |
39 | 39 | |
40 | 40 | private const CASE_FOLD = [ |
41 | - ['µ', 'ſ', "\xCD\x85", 'ς', "\xCF\x90", "\xCF\x91", "\xCF\x95", "\xCF\x96", "\xCF\xB0", "\xCF\xB1", "\xCF\xB5", "\xE1\xBA\x9B", "\xE1\xBE\xBE"], |
|
42 | - ['μ', 's', 'ι', 'σ', 'β', 'θ', 'φ', 'π', 'κ', 'ρ', 'ε', "\xE1\xB9\xA1", 'ι'], |
|
41 | + [ 'µ', 'ſ', "\xCD\x85", 'ς', "\xCF\x90", "\xCF\x91", "\xCF\x95", "\xCF\x96", "\xCF\xB0", "\xCF\xB1", "\xCF\xB5", "\xE1\xBA\x9B", "\xE1\xBE\xBE" ], |
|
42 | + [ 'μ', 's', 'ι', 'σ', 'β', 'θ', 'φ', 'π', 'κ', 'ρ', 'ε', "\xE1\xB9\xA1", 'ι' ], |
|
43 | 43 | ]; |
44 | 44 | |
45 | - public static function grapheme_extract($s, $size, $type = \GRAPHEME_EXTR_COUNT, $start = 0, &$next = 0) |
|
45 | + public static function grapheme_extract( $s, $size, $type = \GRAPHEME_EXTR_COUNT, $start = 0, &$next = 0 ) |
|
46 | 46 | { |
47 | - if (0 > $start) { |
|
48 | - $start = \strlen($s) + $start; |
|
47 | + if ( 0 > $start ) { |
|
48 | + $start = \strlen( $s ) + $start; |
|
49 | 49 | } |
50 | 50 | |
51 | - if (!is_scalar($s)) { |
|
51 | + if ( ! is_scalar( $s ) ) { |
|
52 | 52 | $hasError = false; |
53 | - set_error_handler(function () use (&$hasError) { $hasError = true; }); |
|
54 | - $next = substr($s, $start); |
|
53 | + set_error_handler( function() use ( &$hasError ) { $hasError = true; }); |
|
54 | + $next = substr( $s, $start ); |
|
55 | 55 | restore_error_handler(); |
56 | - if ($hasError) { |
|
57 | - substr($s, $start); |
|
56 | + if ( $hasError ) { |
|
57 | + substr( $s, $start ); |
|
58 | 58 | $s = ''; |
59 | 59 | } else { |
60 | 60 | $s = $next; |
61 | 61 | } |
62 | 62 | } else { |
63 | - $s = substr($s, $start); |
|
63 | + $s = substr( $s, $start ); |
|
64 | 64 | } |
65 | - $size = (int) $size; |
|
66 | - $type = (int) $type; |
|
67 | - $start = (int) $start; |
|
65 | + $size = (int)$size; |
|
66 | + $type = (int)$type; |
|
67 | + $start = (int)$start; |
|
68 | 68 | |
69 | - if (\GRAPHEME_EXTR_COUNT !== $type && \GRAPHEME_EXTR_MAXBYTES !== $type && \GRAPHEME_EXTR_MAXCHARS !== $type) { |
|
70 | - if (80000 > \PHP_VERSION_ID) { |
|
69 | + if ( \GRAPHEME_EXTR_COUNT !== $type && \GRAPHEME_EXTR_MAXBYTES !== $type && \GRAPHEME_EXTR_MAXCHARS !== $type ) { |
|
70 | + if ( 80000 > \PHP_VERSION_ID ) { |
|
71 | 71 | return false; |
72 | 72 | } |
73 | 73 | |
74 | - throw new \ValueError('grapheme_extract(): Argument #3 ($type) must be one of GRAPHEME_EXTR_COUNT, GRAPHEME_EXTR_MAXBYTES, or GRAPHEME_EXTR_MAXCHARS'); |
|
74 | + throw new \ValueError( 'grapheme_extract(): Argument #3 ($type) must be one of GRAPHEME_EXTR_COUNT, GRAPHEME_EXTR_MAXBYTES, or GRAPHEME_EXTR_MAXCHARS' ); |
|
75 | 75 | } |
76 | 76 | |
77 | - if (!isset($s[0]) || 0 > $size || 0 > $start) { |
|
77 | + if ( ! isset( $s[ 0 ] ) || 0 > $size || 0 > $start ) { |
|
78 | 78 | return false; |
79 | 79 | } |
80 | - if (0 === $size) { |
|
80 | + if ( 0 === $size ) { |
|
81 | 81 | return ''; |
82 | 82 | } |
83 | 83 | |
84 | 84 | $next = $start; |
85 | 85 | |
86 | - $s = preg_split('/('.SYMFONY_GRAPHEME_CLUSTER_RX.')/u', "\r\n".$s, $size + 1, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE); |
|
86 | + $s = preg_split( '/(' . SYMFONY_GRAPHEME_CLUSTER_RX . ')/u', "\r\n" . $s, $size + 1, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE ); |
|
87 | 87 | |
88 | - if (!isset($s[1])) { |
|
88 | + if ( ! isset( $s[ 1 ] ) ) { |
|
89 | 89 | return false; |
90 | 90 | } |
91 | 91 | |
@@ -93,125 +93,125 @@ discard block |
||
93 | 93 | $ret = ''; |
94 | 94 | |
95 | 95 | do { |
96 | - if (\GRAPHEME_EXTR_COUNT === $type) { |
|
96 | + if ( \GRAPHEME_EXTR_COUNT === $type ) { |
|
97 | 97 | --$size; |
98 | - } elseif (\GRAPHEME_EXTR_MAXBYTES === $type) { |
|
99 | - $size -= \strlen($s[$i]); |
|
98 | + } elseif ( \GRAPHEME_EXTR_MAXBYTES === $type ) { |
|
99 | + $size -= \strlen( $s[ $i ] ); |
|
100 | 100 | } else { |
101 | - $size -= iconv_strlen($s[$i], 'UTF-8//IGNORE'); |
|
101 | + $size -= iconv_strlen( $s[ $i ], 'UTF-8//IGNORE' ); |
|
102 | 102 | } |
103 | 103 | |
104 | - if ($size >= 0) { |
|
105 | - $ret .= $s[$i]; |
|
104 | + if ( $size >= 0 ) { |
|
105 | + $ret .= $s[ $i ]; |
|
106 | 106 | } |
107 | - } while (isset($s[++$i]) && $size > 0); |
|
107 | + } while ( isset( $s[++$i ] ) && $size > 0 ); |
|
108 | 108 | |
109 | - $next += \strlen($ret); |
|
109 | + $next += \strlen( $ret ); |
|
110 | 110 | |
111 | 111 | return $ret; |
112 | 112 | } |
113 | 113 | |
114 | - public static function grapheme_strlen($s) |
|
114 | + public static function grapheme_strlen( $s ) |
|
115 | 115 | { |
116 | - preg_replace('/'.SYMFONY_GRAPHEME_CLUSTER_RX.'/u', '', $s, -1, $len); |
|
116 | + preg_replace( '/' . SYMFONY_GRAPHEME_CLUSTER_RX . '/u', '', $s, -1, $len ); |
|
117 | 117 | |
118 | 118 | return 0 === $len && '' !== $s ? null : $len; |
119 | 119 | } |
120 | 120 | |
121 | - public static function grapheme_substr($s, $start, $len = null) |
|
121 | + public static function grapheme_substr( $s, $start, $len = null ) |
|
122 | 122 | { |
123 | - if (null === $len) { |
|
123 | + if ( null === $len ) { |
|
124 | 124 | $len = 2147483647; |
125 | 125 | } |
126 | 126 | |
127 | - preg_match_all('/'.SYMFONY_GRAPHEME_CLUSTER_RX.'/u', $s, $s); |
|
127 | + preg_match_all( '/' . SYMFONY_GRAPHEME_CLUSTER_RX . '/u', $s, $s ); |
|
128 | 128 | |
129 | - $slen = \count($s[0]); |
|
130 | - $start = (int) $start; |
|
129 | + $slen = \count( $s[ 0 ] ); |
|
130 | + $start = (int)$start; |
|
131 | 131 | |
132 | - if (0 > $start) { |
|
132 | + if ( 0 > $start ) { |
|
133 | 133 | $start += $slen; |
134 | 134 | } |
135 | - if (0 > $start) { |
|
136 | - if (\PHP_VERSION_ID < 80000) { |
|
135 | + if ( 0 > $start ) { |
|
136 | + if ( \PHP_VERSION_ID < 80000 ) { |
|
137 | 137 | return false; |
138 | 138 | } |
139 | 139 | |
140 | 140 | $start = 0; |
141 | 141 | } |
142 | - if ($start >= $slen) { |
|
142 | + if ( $start >= $slen ) { |
|
143 | 143 | return \PHP_VERSION_ID >= 80000 ? '' : false; |
144 | 144 | } |
145 | 145 | |
146 | 146 | $rem = $slen - $start; |
147 | 147 | |
148 | - if (0 > $len) { |
|
148 | + if ( 0 > $len ) { |
|
149 | 149 | $len += $rem; |
150 | 150 | } |
151 | - if (0 === $len) { |
|
151 | + if ( 0 === $len ) { |
|
152 | 152 | return ''; |
153 | 153 | } |
154 | - if (0 > $len) { |
|
154 | + if ( 0 > $len ) { |
|
155 | 155 | return \PHP_VERSION_ID >= 80000 ? '' : false; |
156 | 156 | } |
157 | - if ($len > $rem) { |
|
157 | + if ( $len > $rem ) { |
|
158 | 158 | $len = $rem; |
159 | 159 | } |
160 | 160 | |
161 | - return implode('', \array_slice($s[0], $start, $len)); |
|
161 | + return implode( '', \array_slice( $s[ 0 ], $start, $len ) ); |
|
162 | 162 | } |
163 | 163 | |
164 | - public static function grapheme_strpos($s, $needle, $offset = 0) |
|
164 | + public static function grapheme_strpos( $s, $needle, $offset = 0 ) |
|
165 | 165 | { |
166 | - return self::grapheme_position($s, $needle, $offset, 0); |
|
166 | + return self::grapheme_position( $s, $needle, $offset, 0 ); |
|
167 | 167 | } |
168 | 168 | |
169 | - public static function grapheme_stripos($s, $needle, $offset = 0) |
|
169 | + public static function grapheme_stripos( $s, $needle, $offset = 0 ) |
|
170 | 170 | { |
171 | - return self::grapheme_position($s, $needle, $offset, 1); |
|
171 | + return self::grapheme_position( $s, $needle, $offset, 1 ); |
|
172 | 172 | } |
173 | 173 | |
174 | - public static function grapheme_strrpos($s, $needle, $offset = 0) |
|
174 | + public static function grapheme_strrpos( $s, $needle, $offset = 0 ) |
|
175 | 175 | { |
176 | - return self::grapheme_position($s, $needle, $offset, 2); |
|
176 | + return self::grapheme_position( $s, $needle, $offset, 2 ); |
|
177 | 177 | } |
178 | 178 | |
179 | - public static function grapheme_strripos($s, $needle, $offset = 0) |
|
179 | + public static function grapheme_strripos( $s, $needle, $offset = 0 ) |
|
180 | 180 | { |
181 | - return self::grapheme_position($s, $needle, $offset, 3); |
|
181 | + return self::grapheme_position( $s, $needle, $offset, 3 ); |
|
182 | 182 | } |
183 | 183 | |
184 | - public static function grapheme_stristr($s, $needle, $beforeNeedle = false) |
|
184 | + public static function grapheme_stristr( $s, $needle, $beforeNeedle = false ) |
|
185 | 185 | { |
186 | - return mb_stristr($s, $needle, $beforeNeedle, 'UTF-8'); |
|
186 | + return mb_stristr( $s, $needle, $beforeNeedle, 'UTF-8' ); |
|
187 | 187 | } |
188 | 188 | |
189 | - public static function grapheme_strstr($s, $needle, $beforeNeedle = false) |
|
189 | + public static function grapheme_strstr( $s, $needle, $beforeNeedle = false ) |
|
190 | 190 | { |
191 | - return mb_strstr($s, $needle, $beforeNeedle, 'UTF-8'); |
|
191 | + return mb_strstr( $s, $needle, $beforeNeedle, 'UTF-8' ); |
|
192 | 192 | } |
193 | 193 | |
194 | - private static function grapheme_position($s, $needle, $offset, $mode) |
|
194 | + private static function grapheme_position( $s, $needle, $offset, $mode ) |
|
195 | 195 | { |
196 | - $needle = (string) $needle; |
|
197 | - if (80000 > \PHP_VERSION_ID && !preg_match('/./us', $needle)) { |
|
196 | + $needle = (string)$needle; |
|
197 | + if ( 80000 > \PHP_VERSION_ID && ! preg_match( '/./us', $needle ) ) { |
|
198 | 198 | return false; |
199 | 199 | } |
200 | - $s = (string) $s; |
|
201 | - if (!preg_match('/./us', $s)) { |
|
200 | + $s = (string)$s; |
|
201 | + if ( ! preg_match( '/./us', $s ) ) { |
|
202 | 202 | return false; |
203 | 203 | } |
204 | - if ($offset > 0) { |
|
205 | - $s = self::grapheme_substr($s, $offset); |
|
206 | - } elseif ($offset < 0) { |
|
207 | - if (2 > $mode) { |
|
208 | - $offset += self::grapheme_strlen($s); |
|
209 | - $s = self::grapheme_substr($s, $offset); |
|
210 | - if (0 > $offset) { |
|
204 | + if ( $offset > 0 ) { |
|
205 | + $s = self::grapheme_substr( $s, $offset ); |
|
206 | + } elseif ( $offset < 0 ) { |
|
207 | + if ( 2 > $mode ) { |
|
208 | + $offset += self::grapheme_strlen( $s ); |
|
209 | + $s = self::grapheme_substr( $s, $offset ); |
|
210 | + if ( 0 > $offset ) { |
|
211 | 211 | $offset = 0; |
212 | 212 | } |
213 | - } elseif (0 > $offset += self::grapheme_strlen($needle)) { |
|
214 | - $s = self::grapheme_substr($s, 0, $offset); |
|
213 | + } elseif ( 0 > $offset += self::grapheme_strlen( $needle ) ) { |
|
214 | + $s = self::grapheme_substr( $s, 0, $offset ); |
|
215 | 215 | $offset = 0; |
216 | 216 | } else { |
217 | 217 | $offset = 0; |
@@ -223,25 +223,25 @@ discard block |
||
223 | 223 | // case fold the strings first. |
224 | 224 | $caseInsensitive = $mode & 1; |
225 | 225 | $reverse = $mode & 2; |
226 | - if ($caseInsensitive) { |
|
226 | + if ( $caseInsensitive ) { |
|
227 | 227 | // Use the same case folding mode as mbstring does for mb_stripos(). |
228 | 228 | // Stick to SIMPLE case folding to avoid changing the length of the string, which |
229 | 229 | // might result in offsets being shifted. |
230 | - $mode = \defined('MB_CASE_FOLD_SIMPLE') ? \MB_CASE_FOLD_SIMPLE : \MB_CASE_LOWER; |
|
231 | - $s = mb_convert_case($s, $mode, 'UTF-8'); |
|
232 | - $needle = mb_convert_case($needle, $mode, 'UTF-8'); |
|
230 | + $mode = \defined( 'MB_CASE_FOLD_SIMPLE' ) ? \MB_CASE_FOLD_SIMPLE : \MB_CASE_LOWER; |
|
231 | + $s = mb_convert_case( $s, $mode, 'UTF-8' ); |
|
232 | + $needle = mb_convert_case( $needle, $mode, 'UTF-8' ); |
|
233 | 233 | |
234 | - if (!\defined('MB_CASE_FOLD_SIMPLE')) { |
|
235 | - $s = str_replace(self::CASE_FOLD[0], self::CASE_FOLD[1], $s); |
|
236 | - $needle = str_replace(self::CASE_FOLD[0], self::CASE_FOLD[1], $needle); |
|
234 | + if ( ! \defined( 'MB_CASE_FOLD_SIMPLE' ) ) { |
|
235 | + $s = str_replace( self::CASE_FOLD[ 0 ], self::CASE_FOLD[ 1 ], $s ); |
|
236 | + $needle = str_replace( self::CASE_FOLD[ 0 ], self::CASE_FOLD[ 1 ], $needle ); |
|
237 | 237 | } |
238 | 238 | } |
239 | - if ($reverse) { |
|
240 | - $needlePos = strrpos($s, $needle); |
|
239 | + if ( $reverse ) { |
|
240 | + $needlePos = strrpos( $s, $needle ); |
|
241 | 241 | } else { |
242 | - $needlePos = strpos($s, $needle); |
|
242 | + $needlePos = strpos( $s, $needle ); |
|
243 | 243 | } |
244 | 244 | |
245 | - return false !== $needlePos ? self::grapheme_strlen(substr($s, 0, $needlePos)) + $offset : false; |
|
245 | + return false !== $needlePos ? self::grapheme_strlen( substr( $s, 0, $needlePos ) ) + $offset : false; |
|
246 | 246 | } |
247 | 247 | } |
@@ -11,40 +11,40 @@ |
||
11 | 11 | |
12 | 12 | use Symfony\Polyfill\Intl\Grapheme as p; |
13 | 13 | |
14 | -if (!defined('GRAPHEME_EXTR_COUNT')) { |
|
15 | - define('GRAPHEME_EXTR_COUNT', 0); |
|
14 | +if ( ! defined( 'GRAPHEME_EXTR_COUNT' ) ) { |
|
15 | + define( 'GRAPHEME_EXTR_COUNT', 0 ); |
|
16 | 16 | } |
17 | -if (!defined('GRAPHEME_EXTR_MAXBYTES')) { |
|
18 | - define('GRAPHEME_EXTR_MAXBYTES', 1); |
|
17 | +if ( ! defined( 'GRAPHEME_EXTR_MAXBYTES' ) ) { |
|
18 | + define( 'GRAPHEME_EXTR_MAXBYTES', 1 ); |
|
19 | 19 | } |
20 | -if (!defined('GRAPHEME_EXTR_MAXCHARS')) { |
|
21 | - define('GRAPHEME_EXTR_MAXCHARS', 2); |
|
20 | +if ( ! defined( 'GRAPHEME_EXTR_MAXCHARS' ) ) { |
|
21 | + define( 'GRAPHEME_EXTR_MAXCHARS', 2 ); |
|
22 | 22 | } |
23 | 23 | |
24 | -if (!function_exists('grapheme_extract')) { |
|
25 | - function grapheme_extract(?string $haystack, ?int $size, ?int $type = GRAPHEME_EXTR_COUNT, ?int $offset = 0, &$next = null): string|false { return p\Grapheme::grapheme_extract((string) $haystack, (int) $size, (int) $type, (int) $offset, $next); } |
|
24 | +if ( ! function_exists( 'grapheme_extract' ) ) { |
|
25 | + function grapheme_extract( ?string $haystack, ?int $size, ?int $type = GRAPHEME_EXTR_COUNT, ?int $offset = 0, &$next = null ): string | false { return p\Grapheme::grapheme_extract( (string)$haystack, (int)$size, (int)$type, (int)$offset, $next ); } |
|
26 | 26 | } |
27 | -if (!function_exists('grapheme_stripos')) { |
|
28 | - function grapheme_stripos(?string $haystack, ?string $needle, ?int $offset = 0): int|false { return p\Grapheme::grapheme_stripos((string) $haystack, (string) $needle, (int) $offset); } |
|
27 | +if ( ! function_exists( 'grapheme_stripos' ) ) { |
|
28 | + function grapheme_stripos( ?string $haystack, ?string $needle, ?int $offset = 0 ): int | false { return p\Grapheme::grapheme_stripos( (string)$haystack, (string)$needle, (int)$offset ); } |
|
29 | 29 | } |
30 | -if (!function_exists('grapheme_stristr')) { |
|
31 | - function grapheme_stristr(?string $haystack, ?string $needle, ?bool $beforeNeedle = false): string|false { return p\Grapheme::grapheme_stristr((string) $haystack, (string) $needle, (bool) $beforeNeedle); } |
|
30 | +if ( ! function_exists( 'grapheme_stristr' ) ) { |
|
31 | + function grapheme_stristr( ?string $haystack, ?string $needle, ?bool $beforeNeedle = false ): string | false { return p\Grapheme::grapheme_stristr( (string)$haystack, (string)$needle, (bool)$beforeNeedle ); } |
|
32 | 32 | } |
33 | -if (!function_exists('grapheme_strlen')) { |
|
34 | - function grapheme_strlen(?string $string): int|false|null { return p\Grapheme::grapheme_strlen((string) $string); } |
|
33 | +if ( ! function_exists( 'grapheme_strlen' ) ) { |
|
34 | + function grapheme_strlen( ?string $string ): int | false | null { return p\Grapheme::grapheme_strlen( (string)$string ); } |
|
35 | 35 | } |
36 | -if (!function_exists('grapheme_strpos')) { |
|
37 | - function grapheme_strpos(?string $haystack, ?string $needle, ?int $offset = 0): int|false { return p\Grapheme::grapheme_strpos((string) $haystack, (string) $needle, (int) $offset); } |
|
36 | +if ( ! function_exists( 'grapheme_strpos' ) ) { |
|
37 | + function grapheme_strpos( ?string $haystack, ?string $needle, ?int $offset = 0 ): int | false { return p\Grapheme::grapheme_strpos( (string)$haystack, (string)$needle, (int)$offset ); } |
|
38 | 38 | } |
39 | -if (!function_exists('grapheme_strripos')) { |
|
40 | - function grapheme_strripos(?string $haystack, ?string $needle, ?int $offset = 0): int|false { return p\Grapheme::grapheme_strripos((string) $haystack, (string) $needle, (int) $offset); } |
|
39 | +if ( ! function_exists( 'grapheme_strripos' ) ) { |
|
40 | + function grapheme_strripos( ?string $haystack, ?string $needle, ?int $offset = 0 ): int | false { return p\Grapheme::grapheme_strripos( (string)$haystack, (string)$needle, (int)$offset ); } |
|
41 | 41 | } |
42 | -if (!function_exists('grapheme_strrpos')) { |
|
43 | - function grapheme_strrpos(?string $haystack, ?string $needle, ?int $offset = 0): int|false { return p\Grapheme::grapheme_strrpos((string) $haystack, (string) $needle, (int) $offset); } |
|
42 | +if ( ! function_exists( 'grapheme_strrpos' ) ) { |
|
43 | + function grapheme_strrpos( ?string $haystack, ?string $needle, ?int $offset = 0 ): int | false { return p\Grapheme::grapheme_strrpos( (string)$haystack, (string)$needle, (int)$offset ); } |
|
44 | 44 | } |
45 | -if (!function_exists('grapheme_strstr')) { |
|
46 | - function grapheme_strstr(?string $haystack, ?string $needle, ?bool $beforeNeedle = false): string|false { return p\Grapheme::grapheme_strstr((string) $haystack, (string) $needle, (bool) $beforeNeedle); } |
|
45 | +if ( ! function_exists( 'grapheme_strstr' ) ) { |
|
46 | + function grapheme_strstr( ?string $haystack, ?string $needle, ?bool $beforeNeedle = false ): string | false { return p\Grapheme::grapheme_strstr( (string)$haystack, (string)$needle, (bool)$beforeNeedle ); } |
|
47 | 47 | } |
48 | -if (!function_exists('grapheme_substr')) { |
|
49 | - function grapheme_substr(?string $string, ?int $offset, ?int $length = null): string|false { return p\Grapheme::grapheme_substr((string) $string, (int) $offset, $length); } |
|
48 | +if ( ! function_exists( 'grapheme_substr' ) ) { |
|
49 | + function grapheme_substr( ?string $string, ?int $offset, ?int $length = null ): string | false { return p\Grapheme::grapheme_substr( (string)$string, (int)$offset, $length ); } |
|
50 | 50 | } |
@@ -15,8 +15,8 @@ discard block |
||
15 | 15 | use Psr\Container\NotFoundExceptionInterface; |
16 | 16 | |
17 | 17 | // Help opcache.preload discover always-needed symbols |
18 | -class_exists(ContainerExceptionInterface::class); |
|
19 | -class_exists(NotFoundExceptionInterface::class); |
|
18 | +class_exists( ContainerExceptionInterface::class ); |
|
19 | +class_exists( NotFoundExceptionInterface::class ); |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * A trait to help implement ServiceProviderInterface. |
@@ -27,13 +27,13 @@ discard block |
||
27 | 27 | trait ServiceLocatorTrait |
28 | 28 | { |
29 | 29 | private $factories; |
30 | - private $loading = []; |
|
30 | + private $loading = [ ]; |
|
31 | 31 | private $providedTypes; |
32 | 32 | |
33 | 33 | /** |
34 | 34 | * @param callable[] $factories |
35 | 35 | */ |
36 | - public function __construct(array $factories) |
|
36 | + public function __construct( array $factories ) |
|
37 | 37 | { |
38 | 38 | $this->factories = $factories; |
39 | 39 | } |
@@ -43,9 +43,9 @@ discard block |
||
43 | 43 | * |
44 | 44 | * @return bool |
45 | 45 | */ |
46 | - public function has(string $id) |
|
46 | + public function has( string $id ) |
|
47 | 47 | { |
48 | - return isset($this->factories[$id]); |
|
48 | + return isset( $this->factories[ $id ] ); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -53,25 +53,25 @@ discard block |
||
53 | 53 | * |
54 | 54 | * @return mixed |
55 | 55 | */ |
56 | - public function get(string $id) |
|
56 | + public function get( string $id ) |
|
57 | 57 | { |
58 | - if (!isset($this->factories[$id])) { |
|
59 | - throw $this->createNotFoundException($id); |
|
58 | + if ( ! isset( $this->factories[ $id ] ) ) { |
|
59 | + throw $this->createNotFoundException( $id ); |
|
60 | 60 | } |
61 | 61 | |
62 | - if (isset($this->loading[$id])) { |
|
63 | - $ids = array_values($this->loading); |
|
64 | - $ids = \array_slice($this->loading, array_search($id, $ids)); |
|
65 | - $ids[] = $id; |
|
62 | + if ( isset( $this->loading[ $id ] ) ) { |
|
63 | + $ids = array_values( $this->loading ); |
|
64 | + $ids = \array_slice( $this->loading, array_search( $id, $ids ) ); |
|
65 | + $ids[ ] = $id; |
|
66 | 66 | |
67 | - throw $this->createCircularReferenceException($id, $ids); |
|
67 | + throw $this->createCircularReferenceException( $id, $ids ); |
|
68 | 68 | } |
69 | 69 | |
70 | - $this->loading[$id] = $id; |
|
70 | + $this->loading[ $id ] = $id; |
|
71 | 71 | try { |
72 | - return $this->factories[$id]($this); |
|
72 | + return $this->factories[ $id ]( $this ); |
|
73 | 73 | } finally { |
74 | - unset($this->loading[$id]); |
|
74 | + unset( $this->loading[ $id ] ); |
|
75 | 75 | } |
76 | 76 | } |
77 | 77 | |
@@ -80,16 +80,16 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function getProvidedServices(): array |
82 | 82 | { |
83 | - if (null === $this->providedTypes) { |
|
84 | - $this->providedTypes = []; |
|
83 | + if ( null === $this->providedTypes ) { |
|
84 | + $this->providedTypes = [ ]; |
|
85 | 85 | |
86 | - foreach ($this->factories as $name => $factory) { |
|
87 | - if (!\is_callable($factory)) { |
|
88 | - $this->providedTypes[$name] = '?'; |
|
86 | + foreach ( $this->factories as $name => $factory ) { |
|
87 | + if ( ! \is_callable( $factory ) ) { |
|
88 | + $this->providedTypes[ $name ] = '?'; |
|
89 | 89 | } else { |
90 | - $type = (new \ReflectionFunction($factory))->getReturnType(); |
|
90 | + $type = ( new \ReflectionFunction( $factory ) )->getReturnType(); |
|
91 | 91 | |
92 | - $this->providedTypes[$name] = $type ? ($type->allowsNull() ? '?' : '').($type instanceof \ReflectionNamedType ? $type->getName() : $type) : '?'; |
|
92 | + $this->providedTypes[ $name ] = $type ? ( $type->allowsNull() ? '?' : '' ) . ( $type instanceof \ReflectionNamedType ? $type->getName() : $type ) : '?'; |
|
93 | 93 | } |
94 | 94 | } |
95 | 95 | } |
@@ -97,32 +97,32 @@ discard block |
||
97 | 97 | return $this->providedTypes; |
98 | 98 | } |
99 | 99 | |
100 | - private function createNotFoundException(string $id): NotFoundExceptionInterface |
|
100 | + private function createNotFoundException( string $id ): NotFoundExceptionInterface |
|
101 | 101 | { |
102 | - if (!$alternatives = array_keys($this->factories)) { |
|
102 | + if ( ! $alternatives = array_keys( $this->factories ) ) { |
|
103 | 103 | $message = 'is empty...'; |
104 | 104 | } else { |
105 | - $last = array_pop($alternatives); |
|
106 | - if ($alternatives) { |
|
107 | - $message = sprintf('only knows about the "%s" and "%s" services.', implode('", "', $alternatives), $last); |
|
105 | + $last = array_pop( $alternatives ); |
|
106 | + if ( $alternatives ) { |
|
107 | + $message = sprintf( 'only knows about the "%s" and "%s" services.', implode( '", "', $alternatives ), $last ); |
|
108 | 108 | } else { |
109 | - $message = sprintf('only knows about the "%s" service.', $last); |
|
109 | + $message = sprintf( 'only knows about the "%s" service.', $last ); |
|
110 | 110 | } |
111 | 111 | } |
112 | 112 | |
113 | - if ($this->loading) { |
|
114 | - $message = sprintf('The service "%s" has a dependency on a non-existent service "%s". This locator %s', end($this->loading), $id, $message); |
|
113 | + if ( $this->loading ) { |
|
114 | + $message = sprintf( 'The service "%s" has a dependency on a non-existent service "%s". This locator %s', end( $this->loading ), $id, $message ); |
|
115 | 115 | } else { |
116 | - $message = sprintf('Service "%s" not found: the current service locator %s', $id, $message); |
|
116 | + $message = sprintf( 'Service "%s" not found: the current service locator %s', $id, $message ); |
|
117 | 117 | } |
118 | 118 | |
119 | - return new class($message) extends \InvalidArgumentException implements NotFoundExceptionInterface { |
|
119 | + return new class( $message ) extends \InvalidArgumentException implements NotFoundExceptionInterface { |
|
120 | 120 | }; |
121 | 121 | } |
122 | 122 | |
123 | - private function createCircularReferenceException(string $id, array $path): ContainerExceptionInterface |
|
123 | + private function createCircularReferenceException( string $id, array $path ): ContainerExceptionInterface |
|
124 | 124 | { |
125 | - return new class(sprintf('Circular reference detected for service "%s", path: "%s".', $id, implode(' -> ', $path))) extends \RuntimeException implements ContainerExceptionInterface { |
|
125 | + return new class( sprintf( 'Circular reference detected for service "%s", path: "%s".', $id, implode( ' -> ', $path ) ) ) extends \RuntimeException implements ContainerExceptionInterface { |
|
126 | 126 | }; |
127 | 127 | } |
128 | 128 | } |
@@ -31,19 +31,19 @@ discard block |
||
31 | 31 | { |
32 | 32 | static $services; |
33 | 33 | |
34 | - if (null !== $services) { |
|
34 | + if ( null !== $services ) { |
|
35 | 35 | return $services; |
36 | 36 | } |
37 | 37 | |
38 | - $services = \is_callable(['parent', __FUNCTION__]) ? parent::getSubscribedServices() : []; |
|
38 | + $services = \is_callable( [ 'parent', __FUNCTION__ ] ) ? parent::getSubscribedServices() : [ ]; |
|
39 | 39 | |
40 | - foreach ((new \ReflectionClass(self::class))->getMethods() as $method) { |
|
41 | - if ($method->isStatic() || $method->isAbstract() || $method->isGenerator() || $method->isInternal() || $method->getNumberOfRequiredParameters()) { |
|
40 | + foreach ( ( new \ReflectionClass( self::class ) )->getMethods() as $method ) { |
|
41 | + if ( $method->isStatic() || $method->isAbstract() || $method->isGenerator() || $method->isInternal() || $method->getNumberOfRequiredParameters() ) { |
|
42 | 42 | continue; |
43 | 43 | } |
44 | 44 | |
45 | - if (self::class === $method->getDeclaringClass()->name && ($returnType = $method->getReturnType()) && !$returnType->isBuiltin()) { |
|
46 | - $services[self::class.'::'.$method->name] = '?'.($returnType instanceof \ReflectionNamedType ? $returnType->getName() : $returnType); |
|
45 | + if ( self::class === $method->getDeclaringClass()->name && ( $returnType = $method->getReturnType() ) && ! $returnType->isBuiltin() ) { |
|
46 | + $services[ self::class . '::' . $method->name ] = '?' . ( $returnType instanceof \ReflectionNamedType ? $returnType->getName() : $returnType ); |
|
47 | 47 | } |
48 | 48 | } |
49 | 49 | |
@@ -53,12 +53,12 @@ discard block |
||
53 | 53 | /** |
54 | 54 | * @required |
55 | 55 | */ |
56 | - public function setContainer(ContainerInterface $container) |
|
56 | + public function setContainer( ContainerInterface $container ) |
|
57 | 57 | { |
58 | 58 | $this->container = $container; |
59 | 59 | |
60 | - if (\is_callable(['parent', __FUNCTION__])) { |
|
61 | - return parent::setContainer($container); |
|
60 | + if ( \is_callable( [ 'parent', __FUNCTION__ ] ) ) { |
|
61 | + return parent::setContainer( $container ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | return null; |
@@ -17,76 +17,76 @@ |
||
17 | 17 | |
18 | 18 | abstract class ServiceLocatorTest extends TestCase |
19 | 19 | { |
20 | - protected function getServiceLocator(array $factories) |
|
20 | + protected function getServiceLocator( array $factories ) |
|
21 | 21 | { |
22 | - return new class($factories) implements ContainerInterface { |
|
22 | + return new class( $factories ) implements ContainerInterface { |
|
23 | 23 | use ServiceLocatorTrait; |
24 | 24 | }; |
25 | 25 | } |
26 | 26 | |
27 | 27 | public function testHas() |
28 | 28 | { |
29 | - $locator = $this->getServiceLocator([ |
|
30 | - 'foo' => function () { return 'bar'; }, |
|
31 | - 'bar' => function () { return 'baz'; }, |
|
32 | - function () { return 'dummy'; }, |
|
33 | - ]); |
|
29 | + $locator = $this->getServiceLocator( [ |
|
30 | + 'foo' => function() { return 'bar'; }, |
|
31 | + 'bar' => function() { return 'baz'; }, |
|
32 | + function() { return 'dummy'; }, |
|
33 | + ] ); |
|
34 | 34 | |
35 | - $this->assertTrue($locator->has('foo')); |
|
36 | - $this->assertTrue($locator->has('bar')); |
|
37 | - $this->assertFalse($locator->has('dummy')); |
|
35 | + $this->assertTrue( $locator->has( 'foo' ) ); |
|
36 | + $this->assertTrue( $locator->has( 'bar' ) ); |
|
37 | + $this->assertFalse( $locator->has( 'dummy' ) ); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | public function testGet() |
41 | 41 | { |
42 | - $locator = $this->getServiceLocator([ |
|
43 | - 'foo' => function () { return 'bar'; }, |
|
44 | - 'bar' => function () { return 'baz'; }, |
|
45 | - ]); |
|
42 | + $locator = $this->getServiceLocator( [ |
|
43 | + 'foo' => function() { return 'bar'; }, |
|
44 | + 'bar' => function() { return 'baz'; }, |
|
45 | + ] ); |
|
46 | 46 | |
47 | - $this->assertSame('bar', $locator->get('foo')); |
|
48 | - $this->assertSame('baz', $locator->get('bar')); |
|
47 | + $this->assertSame( 'bar', $locator->get( 'foo' ) ); |
|
48 | + $this->assertSame( 'baz', $locator->get( 'bar' ) ); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | public function testGetDoesNotMemoize() |
52 | 52 | { |
53 | 53 | $i = 0; |
54 | - $locator = $this->getServiceLocator([ |
|
55 | - 'foo' => function () use (&$i) { |
|
54 | + $locator = $this->getServiceLocator( [ |
|
55 | + 'foo' => function() use ( &$i ) { |
|
56 | 56 | ++$i; |
57 | 57 | |
58 | 58 | return 'bar'; |
59 | 59 | }, |
60 | - ]); |
|
60 | + ] ); |
|
61 | 61 | |
62 | - $this->assertSame('bar', $locator->get('foo')); |
|
63 | - $this->assertSame('bar', $locator->get('foo')); |
|
64 | - $this->assertSame(2, $i); |
|
62 | + $this->assertSame( 'bar', $locator->get( 'foo' ) ); |
|
63 | + $this->assertSame( 'bar', $locator->get( 'foo' ) ); |
|
64 | + $this->assertSame( 2, $i ); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | public function testThrowsOnUndefinedInternalService() |
68 | 68 | { |
69 | - if (!$this->getExpectedException()) { |
|
70 | - $this->expectException(\Psr\Container\NotFoundExceptionInterface::class); |
|
71 | - $this->expectExceptionMessage('The service "foo" has a dependency on a non-existent service "bar". This locator only knows about the "foo" service.'); |
|
69 | + if ( ! $this->getExpectedException() ) { |
|
70 | + $this->expectException( \Psr\Container\NotFoundExceptionInterface::class ); |
|
71 | + $this->expectExceptionMessage( 'The service "foo" has a dependency on a non-existent service "bar". This locator only knows about the "foo" service.' ); |
|
72 | 72 | } |
73 | - $locator = $this->getServiceLocator([ |
|
74 | - 'foo' => function () use (&$locator) { return $locator->get('bar'); }, |
|
75 | - ]); |
|
73 | + $locator = $this->getServiceLocator( [ |
|
74 | + 'foo' => function() use ( &$locator ) { return $locator->get( 'bar' ); }, |
|
75 | + ] ); |
|
76 | 76 | |
77 | - $locator->get('foo'); |
|
77 | + $locator->get( 'foo' ); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | public function testThrowsOnCircularReference() |
81 | 81 | { |
82 | - $this->expectException(\Psr\Container\ContainerExceptionInterface::class); |
|
83 | - $this->expectExceptionMessage('Circular reference detected for service "bar", path: "bar -> baz -> bar".'); |
|
84 | - $locator = $this->getServiceLocator([ |
|
85 | - 'foo' => function () use (&$locator) { return $locator->get('bar'); }, |
|
86 | - 'bar' => function () use (&$locator) { return $locator->get('baz'); }, |
|
87 | - 'baz' => function () use (&$locator) { return $locator->get('bar'); }, |
|
88 | - ]); |
|
82 | + $this->expectException( \Psr\Container\ContainerExceptionInterface::class ); |
|
83 | + $this->expectExceptionMessage( 'Circular reference detected for service "bar", path: "bar -> baz -> bar".' ); |
|
84 | + $locator = $this->getServiceLocator( [ |
|
85 | + 'foo' => function() use ( &$locator ) { return $locator->get( 'bar' ); }, |
|
86 | + 'bar' => function() use ( &$locator ) { return $locator->get( 'baz' ); }, |
|
87 | + 'baz' => function() use ( &$locator ) { return $locator->get( 'bar' ); }, |
|
88 | + ] ); |
|
89 | 89 | |
90 | - $locator->get('foo'); |
|
90 | + $locator->get( 'foo' ); |
|
91 | 91 | } |
92 | 92 | } |
@@ -11,137 +11,137 @@ |
||
11 | 11 | |
12 | 12 | use Symfony\Polyfill\Mbstring as p; |
13 | 13 | |
14 | -if (\PHP_VERSION_ID >= 80000) { |
|
15 | - return require __DIR__.'/bootstrap80.php'; |
|
14 | +if ( \PHP_VERSION_ID >= 80000 ) { |
|
15 | + return require __DIR__ . '/bootstrap80.php'; |
|
16 | 16 | } |
17 | 17 | |
18 | -if (!function_exists('mb_convert_encoding')) { |
|
19 | - function mb_convert_encoding($string, $to_encoding, $from_encoding = null) { return p\Mbstring::mb_convert_encoding($string, $to_encoding, $from_encoding); } |
|
18 | +if ( ! function_exists( 'mb_convert_encoding' ) ) { |
|
19 | + function mb_convert_encoding( $string, $to_encoding, $from_encoding = null ) { return p\Mbstring::mb_convert_encoding( $string, $to_encoding, $from_encoding ); } |
|
20 | 20 | } |
21 | -if (!function_exists('mb_decode_mimeheader')) { |
|
22 | - function mb_decode_mimeheader($string) { return p\Mbstring::mb_decode_mimeheader($string); } |
|
21 | +if ( ! function_exists( 'mb_decode_mimeheader' ) ) { |
|
22 | + function mb_decode_mimeheader( $string ) { return p\Mbstring::mb_decode_mimeheader( $string ); } |
|
23 | 23 | } |
24 | -if (!function_exists('mb_encode_mimeheader')) { |
|
25 | - function mb_encode_mimeheader($string, $charset = null, $transfer_encoding = null, $newline = "\r\n", $indent = 0) { return p\Mbstring::mb_encode_mimeheader($string, $charset, $transfer_encoding, $newline, $indent); } |
|
24 | +if ( ! function_exists( 'mb_encode_mimeheader' ) ) { |
|
25 | + function mb_encode_mimeheader( $string, $charset = null, $transfer_encoding = null, $newline = "\r\n", $indent = 0 ) { return p\Mbstring::mb_encode_mimeheader( $string, $charset, $transfer_encoding, $newline, $indent ); } |
|
26 | 26 | } |
27 | -if (!function_exists('mb_decode_numericentity')) { |
|
28 | - function mb_decode_numericentity($string, $map, $encoding = null) { return p\Mbstring::mb_decode_numericentity($string, $map, $encoding); } |
|
27 | +if ( ! function_exists( 'mb_decode_numericentity' ) ) { |
|
28 | + function mb_decode_numericentity( $string, $map, $encoding = null ) { return p\Mbstring::mb_decode_numericentity( $string, $map, $encoding ); } |
|
29 | 29 | } |
30 | -if (!function_exists('mb_encode_numericentity')) { |
|
31 | - function mb_encode_numericentity($string, $map, $encoding = null, $hex = false) { return p\Mbstring::mb_encode_numericentity($string, $map, $encoding, $hex); } |
|
30 | +if ( ! function_exists( 'mb_encode_numericentity' ) ) { |
|
31 | + function mb_encode_numericentity( $string, $map, $encoding = null, $hex = false ) { return p\Mbstring::mb_encode_numericentity( $string, $map, $encoding, $hex ); } |
|
32 | 32 | } |
33 | -if (!function_exists('mb_convert_case')) { |
|
34 | - function mb_convert_case($string, $mode, $encoding = null) { return p\Mbstring::mb_convert_case($string, $mode, $encoding); } |
|
33 | +if ( ! function_exists( 'mb_convert_case' ) ) { |
|
34 | + function mb_convert_case( $string, $mode, $encoding = null ) { return p\Mbstring::mb_convert_case( $string, $mode, $encoding ); } |
|
35 | 35 | } |
36 | -if (!function_exists('mb_internal_encoding')) { |
|
37 | - function mb_internal_encoding($encoding = null) { return p\Mbstring::mb_internal_encoding($encoding); } |
|
36 | +if ( ! function_exists( 'mb_internal_encoding' ) ) { |
|
37 | + function mb_internal_encoding( $encoding = null ) { return p\Mbstring::mb_internal_encoding( $encoding ); } |
|
38 | 38 | } |
39 | -if (!function_exists('mb_language')) { |
|
40 | - function mb_language($language = null) { return p\Mbstring::mb_language($language); } |
|
39 | +if ( ! function_exists( 'mb_language' ) ) { |
|
40 | + function mb_language( $language = null ) { return p\Mbstring::mb_language( $language ); } |
|
41 | 41 | } |
42 | -if (!function_exists('mb_list_encodings')) { |
|
42 | +if ( ! function_exists( 'mb_list_encodings' ) ) { |
|
43 | 43 | function mb_list_encodings() { return p\Mbstring::mb_list_encodings(); } |
44 | 44 | } |
45 | -if (!function_exists('mb_encoding_aliases')) { |
|
46 | - function mb_encoding_aliases($encoding) { return p\Mbstring::mb_encoding_aliases($encoding); } |
|
45 | +if ( ! function_exists( 'mb_encoding_aliases' ) ) { |
|
46 | + function mb_encoding_aliases( $encoding ) { return p\Mbstring::mb_encoding_aliases( $encoding ); } |
|
47 | 47 | } |
48 | -if (!function_exists('mb_check_encoding')) { |
|
49 | - function mb_check_encoding($value = null, $encoding = null) { return p\Mbstring::mb_check_encoding($value, $encoding); } |
|
48 | +if ( ! function_exists( 'mb_check_encoding' ) ) { |
|
49 | + function mb_check_encoding( $value = null, $encoding = null ) { return p\Mbstring::mb_check_encoding( $value, $encoding ); } |
|
50 | 50 | } |
51 | -if (!function_exists('mb_detect_encoding')) { |
|
52 | - function mb_detect_encoding($string, $encodings = null, $strict = false) { return p\Mbstring::mb_detect_encoding($string, $encodings, $strict); } |
|
51 | +if ( ! function_exists( 'mb_detect_encoding' ) ) { |
|
52 | + function mb_detect_encoding( $string, $encodings = null, $strict = false ) { return p\Mbstring::mb_detect_encoding( $string, $encodings, $strict ); } |
|
53 | 53 | } |
54 | -if (!function_exists('mb_detect_order')) { |
|
55 | - function mb_detect_order($encoding = null) { return p\Mbstring::mb_detect_order($encoding); } |
|
54 | +if ( ! function_exists( 'mb_detect_order' ) ) { |
|
55 | + function mb_detect_order( $encoding = null ) { return p\Mbstring::mb_detect_order( $encoding ); } |
|
56 | 56 | } |
57 | -if (!function_exists('mb_parse_str')) { |
|
58 | - function mb_parse_str($string, &$result = []) { parse_str($string, $result); return (bool) $result; } |
|
57 | +if ( ! function_exists( 'mb_parse_str' ) ) { |
|
58 | + function mb_parse_str( $string, &$result = [ ] ) { parse_str( $string, $result ); return (bool)$result; } |
|
59 | 59 | } |
60 | -if (!function_exists('mb_strlen')) { |
|
61 | - function mb_strlen($string, $encoding = null) { return p\Mbstring::mb_strlen($string, $encoding); } |
|
60 | +if ( ! function_exists( 'mb_strlen' ) ) { |
|
61 | + function mb_strlen( $string, $encoding = null ) { return p\Mbstring::mb_strlen( $string, $encoding ); } |
|
62 | 62 | } |
63 | -if (!function_exists('mb_strpos')) { |
|
64 | - function mb_strpos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_strpos($haystack, $needle, $offset, $encoding); } |
|
63 | +if ( ! function_exists( 'mb_strpos' ) ) { |
|
64 | + function mb_strpos( $haystack, $needle, $offset = 0, $encoding = null ) { return p\Mbstring::mb_strpos( $haystack, $needle, $offset, $encoding ); } |
|
65 | 65 | } |
66 | -if (!function_exists('mb_strtolower')) { |
|
67 | - function mb_strtolower($string, $encoding = null) { return p\Mbstring::mb_strtolower($string, $encoding); } |
|
66 | +if ( ! function_exists( 'mb_strtolower' ) ) { |
|
67 | + function mb_strtolower( $string, $encoding = null ) { return p\Mbstring::mb_strtolower( $string, $encoding ); } |
|
68 | 68 | } |
69 | -if (!function_exists('mb_strtoupper')) { |
|
70 | - function mb_strtoupper($string, $encoding = null) { return p\Mbstring::mb_strtoupper($string, $encoding); } |
|
69 | +if ( ! function_exists( 'mb_strtoupper' ) ) { |
|
70 | + function mb_strtoupper( $string, $encoding = null ) { return p\Mbstring::mb_strtoupper( $string, $encoding ); } |
|
71 | 71 | } |
72 | -if (!function_exists('mb_substitute_character')) { |
|
73 | - function mb_substitute_character($substitute_character = null) { return p\Mbstring::mb_substitute_character($substitute_character); } |
|
72 | +if ( ! function_exists( 'mb_substitute_character' ) ) { |
|
73 | + function mb_substitute_character( $substitute_character = null ) { return p\Mbstring::mb_substitute_character( $substitute_character ); } |
|
74 | 74 | } |
75 | -if (!function_exists('mb_substr')) { |
|
76 | - function mb_substr($string, $start, $length = 2147483647, $encoding = null) { return p\Mbstring::mb_substr($string, $start, $length, $encoding); } |
|
75 | +if ( ! function_exists( 'mb_substr' ) ) { |
|
76 | + function mb_substr( $string, $start, $length = 2147483647, $encoding = null ) { return p\Mbstring::mb_substr( $string, $start, $length, $encoding ); } |
|
77 | 77 | } |
78 | -if (!function_exists('mb_stripos')) { |
|
79 | - function mb_stripos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_stripos($haystack, $needle, $offset, $encoding); } |
|
78 | +if ( ! function_exists( 'mb_stripos' ) ) { |
|
79 | + function mb_stripos( $haystack, $needle, $offset = 0, $encoding = null ) { return p\Mbstring::mb_stripos( $haystack, $needle, $offset, $encoding ); } |
|
80 | 80 | } |
81 | -if (!function_exists('mb_stristr')) { |
|
82 | - function mb_stristr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_stristr($haystack, $needle, $before_needle, $encoding); } |
|
81 | +if ( ! function_exists( 'mb_stristr' ) ) { |
|
82 | + function mb_stristr( $haystack, $needle, $before_needle = false, $encoding = null ) { return p\Mbstring::mb_stristr( $haystack, $needle, $before_needle, $encoding ); } |
|
83 | 83 | } |
84 | -if (!function_exists('mb_strrchr')) { |
|
85 | - function mb_strrchr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_strrchr($haystack, $needle, $before_needle, $encoding); } |
|
84 | +if ( ! function_exists( 'mb_strrchr' ) ) { |
|
85 | + function mb_strrchr( $haystack, $needle, $before_needle = false, $encoding = null ) { return p\Mbstring::mb_strrchr( $haystack, $needle, $before_needle, $encoding ); } |
|
86 | 86 | } |
87 | -if (!function_exists('mb_strrichr')) { |
|
88 | - function mb_strrichr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_strrichr($haystack, $needle, $before_needle, $encoding); } |
|
87 | +if ( ! function_exists( 'mb_strrichr' ) ) { |
|
88 | + function mb_strrichr( $haystack, $needle, $before_needle = false, $encoding = null ) { return p\Mbstring::mb_strrichr( $haystack, $needle, $before_needle, $encoding ); } |
|
89 | 89 | } |
90 | -if (!function_exists('mb_strripos')) { |
|
91 | - function mb_strripos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_strripos($haystack, $needle, $offset, $encoding); } |
|
90 | +if ( ! function_exists( 'mb_strripos' ) ) { |
|
91 | + function mb_strripos( $haystack, $needle, $offset = 0, $encoding = null ) { return p\Mbstring::mb_strripos( $haystack, $needle, $offset, $encoding ); } |
|
92 | 92 | } |
93 | -if (!function_exists('mb_strrpos')) { |
|
94 | - function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_strrpos($haystack, $needle, $offset, $encoding); } |
|
93 | +if ( ! function_exists( 'mb_strrpos' ) ) { |
|
94 | + function mb_strrpos( $haystack, $needle, $offset = 0, $encoding = null ) { return p\Mbstring::mb_strrpos( $haystack, $needle, $offset, $encoding ); } |
|
95 | 95 | } |
96 | -if (!function_exists('mb_strstr')) { |
|
97 | - function mb_strstr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_strstr($haystack, $needle, $before_needle, $encoding); } |
|
96 | +if ( ! function_exists( 'mb_strstr' ) ) { |
|
97 | + function mb_strstr( $haystack, $needle, $before_needle = false, $encoding = null ) { return p\Mbstring::mb_strstr( $haystack, $needle, $before_needle, $encoding ); } |
|
98 | 98 | } |
99 | -if (!function_exists('mb_get_info')) { |
|
100 | - function mb_get_info($type = 'all') { return p\Mbstring::mb_get_info($type); } |
|
99 | +if ( ! function_exists( 'mb_get_info' ) ) { |
|
100 | + function mb_get_info( $type = 'all' ) { return p\Mbstring::mb_get_info( $type ); } |
|
101 | 101 | } |
102 | -if (!function_exists('mb_http_output')) { |
|
103 | - function mb_http_output($encoding = null) { return p\Mbstring::mb_http_output($encoding); } |
|
102 | +if ( ! function_exists( 'mb_http_output' ) ) { |
|
103 | + function mb_http_output( $encoding = null ) { return p\Mbstring::mb_http_output( $encoding ); } |
|
104 | 104 | } |
105 | -if (!function_exists('mb_strwidth')) { |
|
106 | - function mb_strwidth($string, $encoding = null) { return p\Mbstring::mb_strwidth($string, $encoding); } |
|
105 | +if ( ! function_exists( 'mb_strwidth' ) ) { |
|
106 | + function mb_strwidth( $string, $encoding = null ) { return p\Mbstring::mb_strwidth( $string, $encoding ); } |
|
107 | 107 | } |
108 | -if (!function_exists('mb_substr_count')) { |
|
109 | - function mb_substr_count($haystack, $needle, $encoding = null) { return p\Mbstring::mb_substr_count($haystack, $needle, $encoding); } |
|
108 | +if ( ! function_exists( 'mb_substr_count' ) ) { |
|
109 | + function mb_substr_count( $haystack, $needle, $encoding = null ) { return p\Mbstring::mb_substr_count( $haystack, $needle, $encoding ); } |
|
110 | 110 | } |
111 | -if (!function_exists('mb_output_handler')) { |
|
112 | - function mb_output_handler($string, $status) { return p\Mbstring::mb_output_handler($string, $status); } |
|
111 | +if ( ! function_exists( 'mb_output_handler' ) ) { |
|
112 | + function mb_output_handler( $string, $status ) { return p\Mbstring::mb_output_handler( $string, $status ); } |
|
113 | 113 | } |
114 | -if (!function_exists('mb_http_input')) { |
|
115 | - function mb_http_input($type = null) { return p\Mbstring::mb_http_input($type); } |
|
114 | +if ( ! function_exists( 'mb_http_input' ) ) { |
|
115 | + function mb_http_input( $type = null ) { return p\Mbstring::mb_http_input( $type ); } |
|
116 | 116 | } |
117 | 117 | |
118 | -if (!function_exists('mb_convert_variables')) { |
|
119 | - function mb_convert_variables($to_encoding, $from_encoding, &...$vars) { return p\Mbstring::mb_convert_variables($to_encoding, $from_encoding, ...$vars); } |
|
118 | +if ( ! function_exists( 'mb_convert_variables' ) ) { |
|
119 | + function mb_convert_variables( $to_encoding, $from_encoding, &...$vars ) { return p\Mbstring::mb_convert_variables( $to_encoding, $from_encoding, ...$vars ); } |
|
120 | 120 | } |
121 | 121 | |
122 | -if (!function_exists('mb_ord')) { |
|
123 | - function mb_ord($string, $encoding = null) { return p\Mbstring::mb_ord($string, $encoding); } |
|
122 | +if ( ! function_exists( 'mb_ord' ) ) { |
|
123 | + function mb_ord( $string, $encoding = null ) { return p\Mbstring::mb_ord( $string, $encoding ); } |
|
124 | 124 | } |
125 | -if (!function_exists('mb_chr')) { |
|
126 | - function mb_chr($codepoint, $encoding = null) { return p\Mbstring::mb_chr($codepoint, $encoding); } |
|
125 | +if ( ! function_exists( 'mb_chr' ) ) { |
|
126 | + function mb_chr( $codepoint, $encoding = null ) { return p\Mbstring::mb_chr( $codepoint, $encoding ); } |
|
127 | 127 | } |
128 | -if (!function_exists('mb_scrub')) { |
|
129 | - function mb_scrub($string, $encoding = null) { $encoding = null === $encoding ? mb_internal_encoding() : $encoding; return mb_convert_encoding($string, $encoding, $encoding); } |
|
128 | +if ( ! function_exists( 'mb_scrub' ) ) { |
|
129 | + function mb_scrub( $string, $encoding = null ) { $encoding = null === $encoding ? mb_internal_encoding() : $encoding; return mb_convert_encoding( $string, $encoding, $encoding ); } |
|
130 | 130 | } |
131 | -if (!function_exists('mb_str_split')) { |
|
132 | - function mb_str_split($string, $length = 1, $encoding = null) { return p\Mbstring::mb_str_split($string, $length, $encoding); } |
|
131 | +if ( ! function_exists( 'mb_str_split' ) ) { |
|
132 | + function mb_str_split( $string, $length = 1, $encoding = null ) { return p\Mbstring::mb_str_split( $string, $length, $encoding ); } |
|
133 | 133 | } |
134 | 134 | |
135 | -if (extension_loaded('mbstring')) { |
|
135 | +if ( extension_loaded( 'mbstring' ) ) { |
|
136 | 136 | return; |
137 | 137 | } |
138 | 138 | |
139 | -if (!defined('MB_CASE_UPPER')) { |
|
140 | - define('MB_CASE_UPPER', 0); |
|
139 | +if ( ! defined( 'MB_CASE_UPPER' ) ) { |
|
140 | + define( 'MB_CASE_UPPER', 0 ); |
|
141 | 141 | } |
142 | -if (!defined('MB_CASE_LOWER')) { |
|
143 | - define('MB_CASE_LOWER', 1); |
|
142 | +if ( ! defined( 'MB_CASE_LOWER' ) ) { |
|
143 | + define( 'MB_CASE_LOWER', 1 ); |
|
144 | 144 | } |
145 | -if (!defined('MB_CASE_TITLE')) { |
|
146 | - define('MB_CASE_TITLE', 2); |
|
145 | +if ( ! defined( 'MB_CASE_TITLE' ) ) { |
|
146 | + define( 'MB_CASE_TITLE', 2 ); |
|
147 | 147 | } |
@@ -70,57 +70,57 @@ discard block |
||
70 | 70 | public const MB_CASE_FOLD = \PHP_INT_MAX; |
71 | 71 | |
72 | 72 | private const CASE_FOLD = [ |
73 | - ['µ', 'ſ', "\xCD\x85", 'ς', "\xCF\x90", "\xCF\x91", "\xCF\x95", "\xCF\x96", "\xCF\xB0", "\xCF\xB1", "\xCF\xB5", "\xE1\xBA\x9B", "\xE1\xBE\xBE"], |
|
74 | - ['μ', 's', 'ι', 'σ', 'β', 'θ', 'φ', 'π', 'κ', 'ρ', 'ε', "\xE1\xB9\xA1", 'ι'], |
|
73 | + [ 'µ', 'ſ', "\xCD\x85", 'ς', "\xCF\x90", "\xCF\x91", "\xCF\x95", "\xCF\x96", "\xCF\xB0", "\xCF\xB1", "\xCF\xB5", "\xE1\xBA\x9B", "\xE1\xBE\xBE" ], |
|
74 | + [ 'μ', 's', 'ι', 'σ', 'β', 'θ', 'φ', 'π', 'κ', 'ρ', 'ε', "\xE1\xB9\xA1", 'ι' ], |
|
75 | 75 | ]; |
76 | 76 | |
77 | - private static $encodingList = ['ASCII', 'UTF-8']; |
|
77 | + private static $encodingList = [ 'ASCII', 'UTF-8' ]; |
|
78 | 78 | private static $language = 'neutral'; |
79 | 79 | private static $internalEncoding = 'UTF-8'; |
80 | 80 | |
81 | - public static function mb_convert_encoding($s, $toEncoding, $fromEncoding = null) |
|
81 | + public static function mb_convert_encoding( $s, $toEncoding, $fromEncoding = null ) |
|
82 | 82 | { |
83 | - if (\is_array($fromEncoding) || false !== strpos($fromEncoding, ',')) { |
|
84 | - $fromEncoding = self::mb_detect_encoding($s, $fromEncoding); |
|
83 | + if ( \is_array( $fromEncoding ) || false !== strpos( $fromEncoding, ',' ) ) { |
|
84 | + $fromEncoding = self::mb_detect_encoding( $s, $fromEncoding ); |
|
85 | 85 | } else { |
86 | - $fromEncoding = self::getEncoding($fromEncoding); |
|
86 | + $fromEncoding = self::getEncoding( $fromEncoding ); |
|
87 | 87 | } |
88 | 88 | |
89 | - $toEncoding = self::getEncoding($toEncoding); |
|
89 | + $toEncoding = self::getEncoding( $toEncoding ); |
|
90 | 90 | |
91 | - if ('BASE64' === $fromEncoding) { |
|
92 | - $s = base64_decode($s); |
|
91 | + if ( 'BASE64' === $fromEncoding ) { |
|
92 | + $s = base64_decode( $s ); |
|
93 | 93 | $fromEncoding = $toEncoding; |
94 | 94 | } |
95 | 95 | |
96 | - if ('BASE64' === $toEncoding) { |
|
97 | - return base64_encode($s); |
|
96 | + if ( 'BASE64' === $toEncoding ) { |
|
97 | + return base64_encode( $s ); |
|
98 | 98 | } |
99 | 99 | |
100 | - if ('HTML-ENTITIES' === $toEncoding || 'HTML' === $toEncoding) { |
|
101 | - if ('HTML-ENTITIES' === $fromEncoding || 'HTML' === $fromEncoding) { |
|
100 | + if ( 'HTML-ENTITIES' === $toEncoding || 'HTML' === $toEncoding ) { |
|
101 | + if ( 'HTML-ENTITIES' === $fromEncoding || 'HTML' === $fromEncoding ) { |
|
102 | 102 | $fromEncoding = 'Windows-1252'; |
103 | 103 | } |
104 | - if ('UTF-8' !== $fromEncoding) { |
|
105 | - $s = \iconv($fromEncoding, 'UTF-8//IGNORE', $s); |
|
104 | + if ( 'UTF-8' !== $fromEncoding ) { |
|
105 | + $s = \iconv( $fromEncoding, 'UTF-8//IGNORE', $s ); |
|
106 | 106 | } |
107 | 107 | |
108 | - return preg_replace_callback('/[\x80-\xFF]+/', [__CLASS__, 'html_encoding_callback'], $s); |
|
108 | + return preg_replace_callback( '/[\x80-\xFF]+/', [ __CLASS__, 'html_encoding_callback' ], $s ); |
|
109 | 109 | } |
110 | 110 | |
111 | - if ('HTML-ENTITIES' === $fromEncoding) { |
|
112 | - $s = html_entity_decode($s, \ENT_COMPAT, 'UTF-8'); |
|
111 | + if ( 'HTML-ENTITIES' === $fromEncoding ) { |
|
112 | + $s = html_entity_decode( $s, \ENT_COMPAT, 'UTF-8' ); |
|
113 | 113 | $fromEncoding = 'UTF-8'; |
114 | 114 | } |
115 | 115 | |
116 | - return \iconv($fromEncoding, $toEncoding.'//IGNORE', $s); |
|
116 | + return \iconv( $fromEncoding, $toEncoding . '//IGNORE', $s ); |
|
117 | 117 | } |
118 | 118 | |
119 | - public static function mb_convert_variables($toEncoding, $fromEncoding, &...$vars) |
|
119 | + public static function mb_convert_variables( $toEncoding, $fromEncoding, &...$vars ) |
|
120 | 120 | { |
121 | 121 | $ok = true; |
122 | - array_walk_recursive($vars, function (&$v) use (&$ok, $toEncoding, $fromEncoding) { |
|
123 | - if (false === $v = self::mb_convert_encoding($v, $toEncoding, $fromEncoding)) { |
|
122 | + array_walk_recursive( $vars, function( &$v ) use ( &$ok, $toEncoding, $fromEncoding ) { |
|
123 | + if ( false === $v = self::mb_convert_encoding( $v, $toEncoding, $fromEncoding ) ) { |
|
124 | 124 | $ok = false; |
125 | 125 | } |
126 | 126 | }); |
@@ -128,210 +128,210 @@ discard block |
||
128 | 128 | return $ok ? $fromEncoding : false; |
129 | 129 | } |
130 | 130 | |
131 | - public static function mb_decode_mimeheader($s) |
|
131 | + public static function mb_decode_mimeheader( $s ) |
|
132 | 132 | { |
133 | - return \iconv_mime_decode($s, 2, self::$internalEncoding); |
|
133 | + return \iconv_mime_decode( $s, 2, self::$internalEncoding ); |
|
134 | 134 | } |
135 | 135 | |
136 | - public static function mb_encode_mimeheader($s, $charset = null, $transferEncoding = null, $linefeed = null, $indent = null) |
|
136 | + public static function mb_encode_mimeheader( $s, $charset = null, $transferEncoding = null, $linefeed = null, $indent = null ) |
|
137 | 137 | { |
138 | - trigger_error('mb_encode_mimeheader() is bugged. Please use iconv_mime_encode() instead', \E_USER_WARNING); |
|
138 | + trigger_error( 'mb_encode_mimeheader() is bugged. Please use iconv_mime_encode() instead', \E_USER_WARNING ); |
|
139 | 139 | } |
140 | 140 | |
141 | - public static function mb_decode_numericentity($s, $convmap, $encoding = null) |
|
141 | + public static function mb_decode_numericentity( $s, $convmap, $encoding = null ) |
|
142 | 142 | { |
143 | - if (null !== $s && !is_scalar($s) && !(\is_object($s) && method_exists($s, '__toString'))) { |
|
144 | - trigger_error('mb_decode_numericentity() expects parameter 1 to be string, '.\gettype($s).' given', \E_USER_WARNING); |
|
143 | + if ( null !== $s && ! is_scalar( $s ) && ! ( \is_object( $s ) && method_exists( $s, '__toString' ) ) ) { |
|
144 | + trigger_error( 'mb_decode_numericentity() expects parameter 1 to be string, ' . \gettype( $s ) . ' given', \E_USER_WARNING ); |
|
145 | 145 | |
146 | 146 | return null; |
147 | 147 | } |
148 | 148 | |
149 | - if (!\is_array($convmap) || (80000 > \PHP_VERSION_ID && !$convmap)) { |
|
149 | + if ( ! \is_array( $convmap ) || ( 80000 > \PHP_VERSION_ID && ! $convmap ) ) { |
|
150 | 150 | return false; |
151 | 151 | } |
152 | 152 | |
153 | - if (null !== $encoding && !is_scalar($encoding)) { |
|
154 | - trigger_error('mb_decode_numericentity() expects parameter 3 to be string, '.\gettype($s).' given', \E_USER_WARNING); |
|
153 | + if ( null !== $encoding && ! is_scalar( $encoding ) ) { |
|
154 | + trigger_error( 'mb_decode_numericentity() expects parameter 3 to be string, ' . \gettype( $s ) . ' given', \E_USER_WARNING ); |
|
155 | 155 | |
156 | - return ''; // Instead of null (cf. mb_encode_numericentity). |
|
156 | + return ''; // Instead of null (cf. mb_encode_numericentity). |
|
157 | 157 | } |
158 | 158 | |
159 | - $s = (string) $s; |
|
160 | - if ('' === $s) { |
|
159 | + $s = (string)$s; |
|
160 | + if ( '' === $s ) { |
|
161 | 161 | return ''; |
162 | 162 | } |
163 | 163 | |
164 | - $encoding = self::getEncoding($encoding); |
|
164 | + $encoding = self::getEncoding( $encoding ); |
|
165 | 165 | |
166 | - if ('UTF-8' === $encoding) { |
|
166 | + if ( 'UTF-8' === $encoding ) { |
|
167 | 167 | $encoding = null; |
168 | - if (!preg_match('//u', $s)) { |
|
169 | - $s = @\iconv('UTF-8', 'UTF-8//IGNORE', $s); |
|
168 | + if ( ! preg_match( '//u', $s ) ) { |
|
169 | + $s = @\iconv( 'UTF-8', 'UTF-8//IGNORE', $s ); |
|
170 | 170 | } |
171 | 171 | } else { |
172 | - $s = \iconv($encoding, 'UTF-8//IGNORE', $s); |
|
172 | + $s = \iconv( $encoding, 'UTF-8//IGNORE', $s ); |
|
173 | 173 | } |
174 | 174 | |
175 | - $cnt = floor(\count($convmap) / 4) * 4; |
|
175 | + $cnt = floor( \count( $convmap ) / 4 ) * 4; |
|
176 | 176 | |
177 | - for ($i = 0; $i < $cnt; $i += 4) { |
|
177 | + for ( $i = 0; $i < $cnt; $i += 4 ) { |
|
178 | 178 | // collector_decode_htmlnumericentity ignores $convmap[$i + 3] |
179 | - $convmap[$i] += $convmap[$i + 2]; |
|
180 | - $convmap[$i + 1] += $convmap[$i + 2]; |
|
179 | + $convmap[ $i ] += $convmap[ $i + 2 ]; |
|
180 | + $convmap[ $i + 1 ] += $convmap[ $i + 2 ]; |
|
181 | 181 | } |
182 | 182 | |
183 | - $s = preg_replace_callback('/&#(?:0*([0-9]+)|x0*([0-9a-fA-F]+))(?!&);?/', function (array $m) use ($cnt, $convmap) { |
|
184 | - $c = isset($m[2]) ? (int) hexdec($m[2]) : $m[1]; |
|
185 | - for ($i = 0; $i < $cnt; $i += 4) { |
|
186 | - if ($c >= $convmap[$i] && $c <= $convmap[$i + 1]) { |
|
187 | - return self::mb_chr($c - $convmap[$i + 2]); |
|
183 | + $s = preg_replace_callback( '/&#(?:0*([0-9]+)|x0*([0-9a-fA-F]+))(?!&);?/', function( array $m ) use ( $cnt, $convmap ) { |
|
184 | + $c = isset( $m[ 2 ] ) ? (int)hexdec( $m[ 2 ] ) : $m[ 1 ]; |
|
185 | + for ( $i = 0; $i < $cnt; $i += 4 ) { |
|
186 | + if ( $c >= $convmap[ $i ] && $c <= $convmap[ $i + 1 ] ) { |
|
187 | + return self::mb_chr( $c - $convmap[ $i + 2 ] ); |
|
188 | 188 | } |
189 | 189 | } |
190 | 190 | |
191 | - return $m[0]; |
|
192 | - }, $s); |
|
191 | + return $m[ 0 ]; |
|
192 | + }, $s ); |
|
193 | 193 | |
194 | - if (null === $encoding) { |
|
194 | + if ( null === $encoding ) { |
|
195 | 195 | return $s; |
196 | 196 | } |
197 | 197 | |
198 | - return \iconv('UTF-8', $encoding.'//IGNORE', $s); |
|
198 | + return \iconv( 'UTF-8', $encoding . '//IGNORE', $s ); |
|
199 | 199 | } |
200 | 200 | |
201 | - public static function mb_encode_numericentity($s, $convmap, $encoding = null, $is_hex = false) |
|
201 | + public static function mb_encode_numericentity( $s, $convmap, $encoding = null, $is_hex = false ) |
|
202 | 202 | { |
203 | - if (null !== $s && !is_scalar($s) && !(\is_object($s) && method_exists($s, '__toString'))) { |
|
204 | - trigger_error('mb_encode_numericentity() expects parameter 1 to be string, '.\gettype($s).' given', \E_USER_WARNING); |
|
203 | + if ( null !== $s && ! is_scalar( $s ) && ! ( \is_object( $s ) && method_exists( $s, '__toString' ) ) ) { |
|
204 | + trigger_error( 'mb_encode_numericentity() expects parameter 1 to be string, ' . \gettype( $s ) . ' given', \E_USER_WARNING ); |
|
205 | 205 | |
206 | 206 | return null; |
207 | 207 | } |
208 | 208 | |
209 | - if (!\is_array($convmap) || (80000 > \PHP_VERSION_ID && !$convmap)) { |
|
209 | + if ( ! \is_array( $convmap ) || ( 80000 > \PHP_VERSION_ID && ! $convmap ) ) { |
|
210 | 210 | return false; |
211 | 211 | } |
212 | 212 | |
213 | - if (null !== $encoding && !is_scalar($encoding)) { |
|
214 | - trigger_error('mb_encode_numericentity() expects parameter 3 to be string, '.\gettype($s).' given', \E_USER_WARNING); |
|
213 | + if ( null !== $encoding && ! is_scalar( $encoding ) ) { |
|
214 | + trigger_error( 'mb_encode_numericentity() expects parameter 3 to be string, ' . \gettype( $s ) . ' given', \E_USER_WARNING ); |
|
215 | 215 | |
216 | - return null; // Instead of '' (cf. mb_decode_numericentity). |
|
216 | + return null; // Instead of '' (cf. mb_decode_numericentity). |
|
217 | 217 | } |
218 | 218 | |
219 | - if (null !== $is_hex && !is_scalar($is_hex)) { |
|
220 | - trigger_error('mb_encode_numericentity() expects parameter 4 to be boolean, '.\gettype($s).' given', \E_USER_WARNING); |
|
219 | + if ( null !== $is_hex && ! is_scalar( $is_hex ) ) { |
|
220 | + trigger_error( 'mb_encode_numericentity() expects parameter 4 to be boolean, ' . \gettype( $s ) . ' given', \E_USER_WARNING ); |
|
221 | 221 | |
222 | 222 | return null; |
223 | 223 | } |
224 | 224 | |
225 | - $s = (string) $s; |
|
226 | - if ('' === $s) { |
|
225 | + $s = (string)$s; |
|
226 | + if ( '' === $s ) { |
|
227 | 227 | return ''; |
228 | 228 | } |
229 | 229 | |
230 | - $encoding = self::getEncoding($encoding); |
|
230 | + $encoding = self::getEncoding( $encoding ); |
|
231 | 231 | |
232 | - if ('UTF-8' === $encoding) { |
|
232 | + if ( 'UTF-8' === $encoding ) { |
|
233 | 233 | $encoding = null; |
234 | - if (!preg_match('//u', $s)) { |
|
235 | - $s = @\iconv('UTF-8', 'UTF-8//IGNORE', $s); |
|
234 | + if ( ! preg_match( '//u', $s ) ) { |
|
235 | + $s = @\iconv( 'UTF-8', 'UTF-8//IGNORE', $s ); |
|
236 | 236 | } |
237 | 237 | } else { |
238 | - $s = \iconv($encoding, 'UTF-8//IGNORE', $s); |
|
238 | + $s = \iconv( $encoding, 'UTF-8//IGNORE', $s ); |
|
239 | 239 | } |
240 | 240 | |
241 | - static $ulenMask = ["\xC0" => 2, "\xD0" => 2, "\xE0" => 3, "\xF0" => 4]; |
|
241 | + static $ulenMask = [ "\xC0" => 2, "\xD0" => 2, "\xE0" => 3, "\xF0" => 4 ]; |
|
242 | 242 | |
243 | - $cnt = floor(\count($convmap) / 4) * 4; |
|
243 | + $cnt = floor( \count( $convmap ) / 4 ) * 4; |
|
244 | 244 | $i = 0; |
245 | - $len = \strlen($s); |
|
245 | + $len = \strlen( $s ); |
|
246 | 246 | $result = ''; |
247 | 247 | |
248 | - while ($i < $len) { |
|
249 | - $ulen = $s[$i] < "\x80" ? 1 : $ulenMask[$s[$i] & "\xF0"]; |
|
250 | - $uchr = substr($s, $i, $ulen); |
|
248 | + while ( $i < $len ) { |
|
249 | + $ulen = $s[ $i ] < "\x80" ? 1 : $ulenMask[ $s[ $i ] & "\xF0" ]; |
|
250 | + $uchr = substr( $s, $i, $ulen ); |
|
251 | 251 | $i += $ulen; |
252 | - $c = self::mb_ord($uchr); |
|
252 | + $c = self::mb_ord( $uchr ); |
|
253 | 253 | |
254 | - for ($j = 0; $j < $cnt; $j += 4) { |
|
255 | - if ($c >= $convmap[$j] && $c <= $convmap[$j + 1]) { |
|
256 | - $cOffset = ($c + $convmap[$j + 2]) & $convmap[$j + 3]; |
|
257 | - $result .= $is_hex ? sprintf('&#x%X;', $cOffset) : '&#'.$cOffset.';'; |
|
254 | + for ( $j = 0; $j < $cnt; $j += 4 ) { |
|
255 | + if ( $c >= $convmap[ $j ] && $c <= $convmap[ $j + 1 ] ) { |
|
256 | + $cOffset = ( $c + $convmap[ $j + 2 ] ) & $convmap[ $j + 3 ]; |
|
257 | + $result .= $is_hex ? sprintf( '&#x%X;', $cOffset ) : '&#' . $cOffset . ';'; |
|
258 | 258 | continue 2; |
259 | 259 | } |
260 | 260 | } |
261 | 261 | $result .= $uchr; |
262 | 262 | } |
263 | 263 | |
264 | - if (null === $encoding) { |
|
264 | + if ( null === $encoding ) { |
|
265 | 265 | return $result; |
266 | 266 | } |
267 | 267 | |
268 | - return \iconv('UTF-8', $encoding.'//IGNORE', $result); |
|
268 | + return \iconv( 'UTF-8', $encoding . '//IGNORE', $result ); |
|
269 | 269 | } |
270 | 270 | |
271 | - public static function mb_convert_case($s, $mode, $encoding = null) |
|
271 | + public static function mb_convert_case( $s, $mode, $encoding = null ) |
|
272 | 272 | { |
273 | - $s = (string) $s; |
|
274 | - if ('' === $s) { |
|
273 | + $s = (string)$s; |
|
274 | + if ( '' === $s ) { |
|
275 | 275 | return ''; |
276 | 276 | } |
277 | 277 | |
278 | - $encoding = self::getEncoding($encoding); |
|
278 | + $encoding = self::getEncoding( $encoding ); |
|
279 | 279 | |
280 | - if ('UTF-8' === $encoding) { |
|
280 | + if ( 'UTF-8' === $encoding ) { |
|
281 | 281 | $encoding = null; |
282 | - if (!preg_match('//u', $s)) { |
|
283 | - $s = @\iconv('UTF-8', 'UTF-8//IGNORE', $s); |
|
282 | + if ( ! preg_match( '//u', $s ) ) { |
|
283 | + $s = @\iconv( 'UTF-8', 'UTF-8//IGNORE', $s ); |
|
284 | 284 | } |
285 | 285 | } else { |
286 | - $s = \iconv($encoding, 'UTF-8//IGNORE', $s); |
|
286 | + $s = \iconv( $encoding, 'UTF-8//IGNORE', $s ); |
|
287 | 287 | } |
288 | 288 | |
289 | - if (\MB_CASE_TITLE == $mode) { |
|
289 | + if ( \MB_CASE_TITLE == $mode ) { |
|
290 | 290 | static $titleRegexp = null; |
291 | - if (null === $titleRegexp) { |
|
292 | - $titleRegexp = self::getData('titleCaseRegexp'); |
|
291 | + if ( null === $titleRegexp ) { |
|
292 | + $titleRegexp = self::getData( 'titleCaseRegexp' ); |
|
293 | 293 | } |
294 | - $s = preg_replace_callback($titleRegexp, [__CLASS__, 'title_case'], $s); |
|
294 | + $s = preg_replace_callback( $titleRegexp, [ __CLASS__, 'title_case' ], $s ); |
|
295 | 295 | } else { |
296 | - if (\MB_CASE_UPPER == $mode) { |
|
296 | + if ( \MB_CASE_UPPER == $mode ) { |
|
297 | 297 | static $upper = null; |
298 | - if (null === $upper) { |
|
299 | - $upper = self::getData('upperCase'); |
|
298 | + if ( null === $upper ) { |
|
299 | + $upper = self::getData( 'upperCase' ); |
|
300 | 300 | } |
301 | 301 | $map = $upper; |
302 | 302 | } else { |
303 | - if (self::MB_CASE_FOLD === $mode) { |
|
304 | - $s = str_replace(self::CASE_FOLD[0], self::CASE_FOLD[1], $s); |
|
303 | + if ( self::MB_CASE_FOLD === $mode ) { |
|
304 | + $s = str_replace( self::CASE_FOLD[ 0 ], self::CASE_FOLD[ 1 ], $s ); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | static $lower = null; |
308 | - if (null === $lower) { |
|
309 | - $lower = self::getData('lowerCase'); |
|
308 | + if ( null === $lower ) { |
|
309 | + $lower = self::getData( 'lowerCase' ); |
|
310 | 310 | } |
311 | 311 | $map = $lower; |
312 | 312 | } |
313 | 313 | |
314 | - static $ulenMask = ["\xC0" => 2, "\xD0" => 2, "\xE0" => 3, "\xF0" => 4]; |
|
314 | + static $ulenMask = [ "\xC0" => 2, "\xD0" => 2, "\xE0" => 3, "\xF0" => 4 ]; |
|
315 | 315 | |
316 | 316 | $i = 0; |
317 | - $len = \strlen($s); |
|
317 | + $len = \strlen( $s ); |
|
318 | 318 | |
319 | - while ($i < $len) { |
|
320 | - $ulen = $s[$i] < "\x80" ? 1 : $ulenMask[$s[$i] & "\xF0"]; |
|
321 | - $uchr = substr($s, $i, $ulen); |
|
319 | + while ( $i < $len ) { |
|
320 | + $ulen = $s[ $i ] < "\x80" ? 1 : $ulenMask[ $s[ $i ] & "\xF0" ]; |
|
321 | + $uchr = substr( $s, $i, $ulen ); |
|
322 | 322 | $i += $ulen; |
323 | 323 | |
324 | - if (isset($map[$uchr])) { |
|
325 | - $uchr = $map[$uchr]; |
|
326 | - $nlen = \strlen($uchr); |
|
324 | + if ( isset( $map[ $uchr ] ) ) { |
|
325 | + $uchr = $map[ $uchr ]; |
|
326 | + $nlen = \strlen( $uchr ); |
|
327 | 327 | |
328 | - if ($nlen == $ulen) { |
|
328 | + if ( $nlen == $ulen ) { |
|
329 | 329 | $nlen = $i; |
330 | 330 | do { |
331 | - $s[--$nlen] = $uchr[--$ulen]; |
|
332 | - } while ($ulen); |
|
331 | + $s[--$nlen ] = $uchr[--$ulen ]; |
|
332 | + } while ( $ulen ); |
|
333 | 333 | } else { |
334 | - $s = substr_replace($s, $uchr, $i - $ulen, $ulen); |
|
334 | + $s = substr_replace( $s, $uchr, $i - $ulen, $ulen ); |
|
335 | 335 | $len += $nlen - $ulen; |
336 | 336 | $i += $nlen - $ulen; |
337 | 337 | } |
@@ -339,41 +339,41 @@ discard block |
||
339 | 339 | } |
340 | 340 | } |
341 | 341 | |
342 | - if (null === $encoding) { |
|
342 | + if ( null === $encoding ) { |
|
343 | 343 | return $s; |
344 | 344 | } |
345 | 345 | |
346 | - return \iconv('UTF-8', $encoding.'//IGNORE', $s); |
|
346 | + return \iconv( 'UTF-8', $encoding . '//IGNORE', $s ); |
|
347 | 347 | } |
348 | 348 | |
349 | - public static function mb_internal_encoding($encoding = null) |
|
349 | + public static function mb_internal_encoding( $encoding = null ) |
|
350 | 350 | { |
351 | - if (null === $encoding) { |
|
351 | + if ( null === $encoding ) { |
|
352 | 352 | return self::$internalEncoding; |
353 | 353 | } |
354 | 354 | |
355 | - $normalizedEncoding = self::getEncoding($encoding); |
|
355 | + $normalizedEncoding = self::getEncoding( $encoding ); |
|
356 | 356 | |
357 | - if ('UTF-8' === $normalizedEncoding || false !== @\iconv($normalizedEncoding, $normalizedEncoding, ' ')) { |
|
357 | + if ( 'UTF-8' === $normalizedEncoding || false !== @\iconv( $normalizedEncoding, $normalizedEncoding, ' ' ) ) { |
|
358 | 358 | self::$internalEncoding = $normalizedEncoding; |
359 | 359 | |
360 | 360 | return true; |
361 | 361 | } |
362 | 362 | |
363 | - if (80000 > \PHP_VERSION_ID) { |
|
363 | + if ( 80000 > \PHP_VERSION_ID ) { |
|
364 | 364 | return false; |
365 | 365 | } |
366 | 366 | |
367 | - throw new \ValueError(sprintf('Argument #1 ($encoding) must be a valid encoding, "%s" given', $encoding)); |
|
367 | + throw new \ValueError( sprintf( 'Argument #1 ($encoding) must be a valid encoding, "%s" given', $encoding ) ); |
|
368 | 368 | } |
369 | 369 | |
370 | - public static function mb_language($lang = null) |
|
370 | + public static function mb_language( $lang = null ) |
|
371 | 371 | { |
372 | - if (null === $lang) { |
|
372 | + if ( null === $lang ) { |
|
373 | 373 | return self::$language; |
374 | 374 | } |
375 | 375 | |
376 | - switch ($normalizedLang = strtolower($lang)) { |
|
376 | + switch ( $normalizedLang = strtolower( $lang ) ) { |
|
377 | 377 | case 'uni': |
378 | 378 | case 'neutral': |
379 | 379 | self::$language = $normalizedLang; |
@@ -381,69 +381,69 @@ discard block |
||
381 | 381 | return true; |
382 | 382 | } |
383 | 383 | |
384 | - if (80000 > \PHP_VERSION_ID) { |
|
384 | + if ( 80000 > \PHP_VERSION_ID ) { |
|
385 | 385 | return false; |
386 | 386 | } |
387 | 387 | |
388 | - throw new \ValueError(sprintf('Argument #1 ($language) must be a valid language, "%s" given', $lang)); |
|
388 | + throw new \ValueError( sprintf( 'Argument #1 ($language) must be a valid language, "%s" given', $lang ) ); |
|
389 | 389 | } |
390 | 390 | |
391 | 391 | public static function mb_list_encodings() |
392 | 392 | { |
393 | - return ['UTF-8']; |
|
393 | + return [ 'UTF-8' ]; |
|
394 | 394 | } |
395 | 395 | |
396 | - public static function mb_encoding_aliases($encoding) |
|
396 | + public static function mb_encoding_aliases( $encoding ) |
|
397 | 397 | { |
398 | - switch (strtoupper($encoding)) { |
|
398 | + switch ( strtoupper( $encoding ) ) { |
|
399 | 399 | case 'UTF8': |
400 | 400 | case 'UTF-8': |
401 | - return ['utf8']; |
|
401 | + return [ 'utf8' ]; |
|
402 | 402 | } |
403 | 403 | |
404 | 404 | return false; |
405 | 405 | } |
406 | 406 | |
407 | - public static function mb_check_encoding($var = null, $encoding = null) |
|
407 | + public static function mb_check_encoding( $var = null, $encoding = null ) |
|
408 | 408 | { |
409 | - if (null === $encoding) { |
|
410 | - if (null === $var) { |
|
409 | + if ( null === $encoding ) { |
|
410 | + if ( null === $var ) { |
|
411 | 411 | return false; |
412 | 412 | } |
413 | 413 | $encoding = self::$internalEncoding; |
414 | 414 | } |
415 | 415 | |
416 | - return self::mb_detect_encoding($var, [$encoding]) || false !== @\iconv($encoding, $encoding, $var); |
|
416 | + return self::mb_detect_encoding( $var, [ $encoding ] ) || false !== @\iconv( $encoding, $encoding, $var ); |
|
417 | 417 | } |
418 | 418 | |
419 | - public static function mb_detect_encoding($str, $encodingList = null, $strict = false) |
|
419 | + public static function mb_detect_encoding( $str, $encodingList = null, $strict = false ) |
|
420 | 420 | { |
421 | - if (null === $encodingList) { |
|
421 | + if ( null === $encodingList ) { |
|
422 | 422 | $encodingList = self::$encodingList; |
423 | 423 | } else { |
424 | - if (!\is_array($encodingList)) { |
|
425 | - $encodingList = array_map('trim', explode(',', $encodingList)); |
|
424 | + if ( ! \is_array( $encodingList ) ) { |
|
425 | + $encodingList = array_map( 'trim', explode( ',', $encodingList ) ); |
|
426 | 426 | } |
427 | - $encodingList = array_map('strtoupper', $encodingList); |
|
427 | + $encodingList = array_map( 'strtoupper', $encodingList ); |
|
428 | 428 | } |
429 | 429 | |
430 | - foreach ($encodingList as $enc) { |
|
431 | - switch ($enc) { |
|
430 | + foreach ( $encodingList as $enc ) { |
|
431 | + switch ( $enc ) { |
|
432 | 432 | case 'ASCII': |
433 | - if (!preg_match('/[\x80-\xFF]/', $str)) { |
|
433 | + if ( ! preg_match( '/[\x80-\xFF]/', $str ) ) { |
|
434 | 434 | return $enc; |
435 | 435 | } |
436 | 436 | break; |
437 | 437 | |
438 | 438 | case 'UTF8': |
439 | 439 | case 'UTF-8': |
440 | - if (preg_match('//u', $str)) { |
|
440 | + if ( preg_match( '//u', $str ) ) { |
|
441 | 441 | return 'UTF-8'; |
442 | 442 | } |
443 | 443 | break; |
444 | 444 | |
445 | 445 | default: |
446 | - if (0 === strncmp($enc, 'ISO-8859-', 9)) { |
|
446 | + if ( 0 === strncmp( $enc, 'ISO-8859-', 9 ) ) { |
|
447 | 447 | return $enc; |
448 | 448 | } |
449 | 449 | } |
@@ -452,21 +452,21 @@ discard block |
||
452 | 452 | return false; |
453 | 453 | } |
454 | 454 | |
455 | - public static function mb_detect_order($encodingList = null) |
|
455 | + public static function mb_detect_order( $encodingList = null ) |
|
456 | 456 | { |
457 | - if (null === $encodingList) { |
|
457 | + if ( null === $encodingList ) { |
|
458 | 458 | return self::$encodingList; |
459 | 459 | } |
460 | 460 | |
461 | - if (!\is_array($encodingList)) { |
|
462 | - $encodingList = array_map('trim', explode(',', $encodingList)); |
|
461 | + if ( ! \is_array( $encodingList ) ) { |
|
462 | + $encodingList = array_map( 'trim', explode( ',', $encodingList ) ); |
|
463 | 463 | } |
464 | - $encodingList = array_map('strtoupper', $encodingList); |
|
464 | + $encodingList = array_map( 'strtoupper', $encodingList ); |
|
465 | 465 | |
466 | - foreach ($encodingList as $enc) { |
|
467 | - switch ($enc) { |
|
466 | + foreach ( $encodingList as $enc ) { |
|
467 | + switch ( $enc ) { |
|
468 | 468 | default: |
469 | - if (strncmp($enc, 'ISO-8859-', 9)) { |
|
469 | + if ( strncmp( $enc, 'ISO-8859-', 9 ) ) { |
|
470 | 470 | return false; |
471 | 471 | } |
472 | 472 | // no break |
@@ -481,27 +481,27 @@ discard block |
||
481 | 481 | return true; |
482 | 482 | } |
483 | 483 | |
484 | - public static function mb_strlen($s, $encoding = null) |
|
484 | + public static function mb_strlen( $s, $encoding = null ) |
|
485 | 485 | { |
486 | - $encoding = self::getEncoding($encoding); |
|
487 | - if ('CP850' === $encoding || 'ASCII' === $encoding) { |
|
488 | - return \strlen($s); |
|
486 | + $encoding = self::getEncoding( $encoding ); |
|
487 | + if ( 'CP850' === $encoding || 'ASCII' === $encoding ) { |
|
488 | + return \strlen( $s ); |
|
489 | 489 | } |
490 | 490 | |
491 | - return @\iconv_strlen($s, $encoding); |
|
491 | + return @\iconv_strlen( $s, $encoding ); |
|
492 | 492 | } |
493 | 493 | |
494 | - public static function mb_strpos($haystack, $needle, $offset = 0, $encoding = null) |
|
494 | + public static function mb_strpos( $haystack, $needle, $offset = 0, $encoding = null ) |
|
495 | 495 | { |
496 | - $encoding = self::getEncoding($encoding); |
|
497 | - if ('CP850' === $encoding || 'ASCII' === $encoding) { |
|
498 | - return strpos($haystack, $needle, $offset); |
|
496 | + $encoding = self::getEncoding( $encoding ); |
|
497 | + if ( 'CP850' === $encoding || 'ASCII' === $encoding ) { |
|
498 | + return strpos( $haystack, $needle, $offset ); |
|
499 | 499 | } |
500 | 500 | |
501 | - $needle = (string) $needle; |
|
502 | - if ('' === $needle) { |
|
503 | - if (80000 > \PHP_VERSION_ID) { |
|
504 | - trigger_error(__METHOD__.': Empty delimiter', \E_USER_WARNING); |
|
501 | + $needle = (string)$needle; |
|
502 | + if ( '' === $needle ) { |
|
503 | + if ( 80000 > \PHP_VERSION_ID ) { |
|
504 | + trigger_error( __METHOD__ . ': Empty delimiter', \E_USER_WARNING ); |
|
505 | 505 | |
506 | 506 | return false; |
507 | 507 | } |
@@ -509,187 +509,187 @@ discard block |
||
509 | 509 | return 0; |
510 | 510 | } |
511 | 511 | |
512 | - return \iconv_strpos($haystack, $needle, $offset, $encoding); |
|
512 | + return \iconv_strpos( $haystack, $needle, $offset, $encoding ); |
|
513 | 513 | } |
514 | 514 | |
515 | - public static function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null) |
|
515 | + public static function mb_strrpos( $haystack, $needle, $offset = 0, $encoding = null ) |
|
516 | 516 | { |
517 | - $encoding = self::getEncoding($encoding); |
|
518 | - if ('CP850' === $encoding || 'ASCII' === $encoding) { |
|
519 | - return strrpos($haystack, $needle, $offset); |
|
517 | + $encoding = self::getEncoding( $encoding ); |
|
518 | + if ( 'CP850' === $encoding || 'ASCII' === $encoding ) { |
|
519 | + return strrpos( $haystack, $needle, $offset ); |
|
520 | 520 | } |
521 | 521 | |
522 | - if ($offset != (int) $offset) { |
|
522 | + if ( $offset != (int)$offset ) { |
|
523 | 523 | $offset = 0; |
524 | - } elseif ($offset = (int) $offset) { |
|
525 | - if ($offset < 0) { |
|
526 | - if (0 > $offset += self::mb_strlen($needle)) { |
|
527 | - $haystack = self::mb_substr($haystack, 0, $offset, $encoding); |
|
524 | + } elseif ( $offset = (int)$offset ) { |
|
525 | + if ( $offset < 0 ) { |
|
526 | + if ( 0 > $offset += self::mb_strlen( $needle ) ) { |
|
527 | + $haystack = self::mb_substr( $haystack, 0, $offset, $encoding ); |
|
528 | 528 | } |
529 | 529 | $offset = 0; |
530 | 530 | } else { |
531 | - $haystack = self::mb_substr($haystack, $offset, 2147483647, $encoding); |
|
531 | + $haystack = self::mb_substr( $haystack, $offset, 2147483647, $encoding ); |
|
532 | 532 | } |
533 | 533 | } |
534 | 534 | |
535 | 535 | $pos = '' !== $needle || 80000 > \PHP_VERSION_ID |
536 | - ? \iconv_strrpos($haystack, $needle, $encoding) |
|
537 | - : self::mb_strlen($haystack, $encoding); |
|
536 | + ? \iconv_strrpos( $haystack, $needle, $encoding ) |
|
537 | + : self::mb_strlen( $haystack, $encoding ); |
|
538 | 538 | |
539 | 539 | return false !== $pos ? $offset + $pos : false; |
540 | 540 | } |
541 | 541 | |
542 | - public static function mb_str_split($string, $split_length = 1, $encoding = null) |
|
542 | + public static function mb_str_split( $string, $split_length = 1, $encoding = null ) |
|
543 | 543 | { |
544 | - if (null !== $string && !is_scalar($string) && !(\is_object($string) && method_exists($string, '__toString'))) { |
|
545 | - trigger_error('mb_str_split() expects parameter 1 to be string, '.\gettype($string).' given', \E_USER_WARNING); |
|
544 | + if ( null !== $string && ! is_scalar( $string ) && ! ( \is_object( $string ) && method_exists( $string, '__toString' ) ) ) { |
|
545 | + trigger_error( 'mb_str_split() expects parameter 1 to be string, ' . \gettype( $string ) . ' given', \E_USER_WARNING ); |
|
546 | 546 | |
547 | 547 | return null; |
548 | 548 | } |
549 | 549 | |
550 | - if (1 > $split_length = (int) $split_length) { |
|
551 | - if (80000 > \PHP_VERSION_ID) { |
|
552 | - trigger_error('The length of each segment must be greater than zero', \E_USER_WARNING); |
|
550 | + if ( 1 > $split_length = (int)$split_length ) { |
|
551 | + if ( 80000 > \PHP_VERSION_ID ) { |
|
552 | + trigger_error( 'The length of each segment must be greater than zero', \E_USER_WARNING ); |
|
553 | 553 | return false; |
554 | 554 | } |
555 | 555 | |
556 | - throw new \ValueError('Argument #2 ($length) must be greater than 0'); |
|
556 | + throw new \ValueError( 'Argument #2 ($length) must be greater than 0' ); |
|
557 | 557 | } |
558 | 558 | |
559 | - if (null === $encoding) { |
|
559 | + if ( null === $encoding ) { |
|
560 | 560 | $encoding = mb_internal_encoding(); |
561 | 561 | } |
562 | 562 | |
563 | - if ('UTF-8' === $encoding = self::getEncoding($encoding)) { |
|
563 | + if ( 'UTF-8' === $encoding = self::getEncoding( $encoding ) ) { |
|
564 | 564 | $rx = '/('; |
565 | - while (65535 < $split_length) { |
|
565 | + while ( 65535 < $split_length ) { |
|
566 | 566 | $rx .= '.{65535}'; |
567 | 567 | $split_length -= 65535; |
568 | 568 | } |
569 | - $rx .= '.{'.$split_length.'})/us'; |
|
569 | + $rx .= '.{' . $split_length . '})/us'; |
|
570 | 570 | |
571 | - return preg_split($rx, $string, null, \PREG_SPLIT_DELIM_CAPTURE | \PREG_SPLIT_NO_EMPTY); |
|
571 | + return preg_split( $rx, $string, null, \PREG_SPLIT_DELIM_CAPTURE | \PREG_SPLIT_NO_EMPTY ); |
|
572 | 572 | } |
573 | 573 | |
574 | - $result = []; |
|
575 | - $length = mb_strlen($string, $encoding); |
|
574 | + $result = [ ]; |
|
575 | + $length = mb_strlen( $string, $encoding ); |
|
576 | 576 | |
577 | - for ($i = 0; $i < $length; $i += $split_length) { |
|
578 | - $result[] = mb_substr($string, $i, $split_length, $encoding); |
|
577 | + for ( $i = 0; $i < $length; $i += $split_length ) { |
|
578 | + $result[ ] = mb_substr( $string, $i, $split_length, $encoding ); |
|
579 | 579 | } |
580 | 580 | |
581 | 581 | return $result; |
582 | 582 | } |
583 | 583 | |
584 | - public static function mb_strtolower($s, $encoding = null) |
|
584 | + public static function mb_strtolower( $s, $encoding = null ) |
|
585 | 585 | { |
586 | - return self::mb_convert_case($s, \MB_CASE_LOWER, $encoding); |
|
586 | + return self::mb_convert_case( $s, \MB_CASE_LOWER, $encoding ); |
|
587 | 587 | } |
588 | 588 | |
589 | - public static function mb_strtoupper($s, $encoding = null) |
|
589 | + public static function mb_strtoupper( $s, $encoding = null ) |
|
590 | 590 | { |
591 | - return self::mb_convert_case($s, \MB_CASE_UPPER, $encoding); |
|
591 | + return self::mb_convert_case( $s, \MB_CASE_UPPER, $encoding ); |
|
592 | 592 | } |
593 | 593 | |
594 | - public static function mb_substitute_character($c = null) |
|
594 | + public static function mb_substitute_character( $c = null ) |
|
595 | 595 | { |
596 | - if (null === $c) { |
|
596 | + if ( null === $c ) { |
|
597 | 597 | return 'none'; |
598 | 598 | } |
599 | - if (0 === strcasecmp($c, 'none')) { |
|
599 | + if ( 0 === strcasecmp( $c, 'none' ) ) { |
|
600 | 600 | return true; |
601 | 601 | } |
602 | - if (80000 > \PHP_VERSION_ID) { |
|
602 | + if ( 80000 > \PHP_VERSION_ID ) { |
|
603 | 603 | return false; |
604 | 604 | } |
605 | 605 | |
606 | - throw new \ValueError('Argument #1 ($substitute_character) must be "none", "long", "entity" or a valid codepoint'); |
|
606 | + throw new \ValueError( 'Argument #1 ($substitute_character) must be "none", "long", "entity" or a valid codepoint' ); |
|
607 | 607 | } |
608 | 608 | |
609 | - public static function mb_substr($s, $start, $length = null, $encoding = null) |
|
609 | + public static function mb_substr( $s, $start, $length = null, $encoding = null ) |
|
610 | 610 | { |
611 | - $encoding = self::getEncoding($encoding); |
|
612 | - if ('CP850' === $encoding || 'ASCII' === $encoding) { |
|
613 | - return (string) substr($s, $start, null === $length ? 2147483647 : $length); |
|
611 | + $encoding = self::getEncoding( $encoding ); |
|
612 | + if ( 'CP850' === $encoding || 'ASCII' === $encoding ) { |
|
613 | + return (string)substr( $s, $start, null === $length ? 2147483647 : $length ); |
|
614 | 614 | } |
615 | 615 | |
616 | - if ($start < 0) { |
|
617 | - $start = \iconv_strlen($s, $encoding) + $start; |
|
618 | - if ($start < 0) { |
|
616 | + if ( $start < 0 ) { |
|
617 | + $start = \iconv_strlen( $s, $encoding ) + $start; |
|
618 | + if ( $start < 0 ) { |
|
619 | 619 | $start = 0; |
620 | 620 | } |
621 | 621 | } |
622 | 622 | |
623 | - if (null === $length) { |
|
623 | + if ( null === $length ) { |
|
624 | 624 | $length = 2147483647; |
625 | - } elseif ($length < 0) { |
|
626 | - $length = \iconv_strlen($s, $encoding) + $length - $start; |
|
627 | - if ($length < 0) { |
|
625 | + } elseif ( $length < 0 ) { |
|
626 | + $length = \iconv_strlen( $s, $encoding ) + $length - $start; |
|
627 | + if ( $length < 0 ) { |
|
628 | 628 | return ''; |
629 | 629 | } |
630 | 630 | } |
631 | 631 | |
632 | - return (string) \iconv_substr($s, $start, $length, $encoding); |
|
632 | + return (string)\iconv_substr( $s, $start, $length, $encoding ); |
|
633 | 633 | } |
634 | 634 | |
635 | - public static function mb_stripos($haystack, $needle, $offset = 0, $encoding = null) |
|
635 | + public static function mb_stripos( $haystack, $needle, $offset = 0, $encoding = null ) |
|
636 | 636 | { |
637 | - $haystack = self::mb_convert_case($haystack, self::MB_CASE_FOLD, $encoding); |
|
638 | - $needle = self::mb_convert_case($needle, self::MB_CASE_FOLD, $encoding); |
|
637 | + $haystack = self::mb_convert_case( $haystack, self::MB_CASE_FOLD, $encoding ); |
|
638 | + $needle = self::mb_convert_case( $needle, self::MB_CASE_FOLD, $encoding ); |
|
639 | 639 | |
640 | - return self::mb_strpos($haystack, $needle, $offset, $encoding); |
|
640 | + return self::mb_strpos( $haystack, $needle, $offset, $encoding ); |
|
641 | 641 | } |
642 | 642 | |
643 | - public static function mb_stristr($haystack, $needle, $part = false, $encoding = null) |
|
643 | + public static function mb_stristr( $haystack, $needle, $part = false, $encoding = null ) |
|
644 | 644 | { |
645 | - $pos = self::mb_stripos($haystack, $needle, 0, $encoding); |
|
645 | + $pos = self::mb_stripos( $haystack, $needle, 0, $encoding ); |
|
646 | 646 | |
647 | - return self::getSubpart($pos, $part, $haystack, $encoding); |
|
647 | + return self::getSubpart( $pos, $part, $haystack, $encoding ); |
|
648 | 648 | } |
649 | 649 | |
650 | - public static function mb_strrchr($haystack, $needle, $part = false, $encoding = null) |
|
650 | + public static function mb_strrchr( $haystack, $needle, $part = false, $encoding = null ) |
|
651 | 651 | { |
652 | - $encoding = self::getEncoding($encoding); |
|
653 | - if ('CP850' === $encoding || 'ASCII' === $encoding) { |
|
654 | - $pos = strrpos($haystack, $needle); |
|
652 | + $encoding = self::getEncoding( $encoding ); |
|
653 | + if ( 'CP850' === $encoding || 'ASCII' === $encoding ) { |
|
654 | + $pos = strrpos( $haystack, $needle ); |
|
655 | 655 | } else { |
656 | - $needle = self::mb_substr($needle, 0, 1, $encoding); |
|
657 | - $pos = \iconv_strrpos($haystack, $needle, $encoding); |
|
656 | + $needle = self::mb_substr( $needle, 0, 1, $encoding ); |
|
657 | + $pos = \iconv_strrpos( $haystack, $needle, $encoding ); |
|
658 | 658 | } |
659 | 659 | |
660 | - return self::getSubpart($pos, $part, $haystack, $encoding); |
|
660 | + return self::getSubpart( $pos, $part, $haystack, $encoding ); |
|
661 | 661 | } |
662 | 662 | |
663 | - public static function mb_strrichr($haystack, $needle, $part = false, $encoding = null) |
|
663 | + public static function mb_strrichr( $haystack, $needle, $part = false, $encoding = null ) |
|
664 | 664 | { |
665 | - $needle = self::mb_substr($needle, 0, 1, $encoding); |
|
666 | - $pos = self::mb_strripos($haystack, $needle, $encoding); |
|
665 | + $needle = self::mb_substr( $needle, 0, 1, $encoding ); |
|
666 | + $pos = self::mb_strripos( $haystack, $needle, $encoding ); |
|
667 | 667 | |
668 | - return self::getSubpart($pos, $part, $haystack, $encoding); |
|
668 | + return self::getSubpart( $pos, $part, $haystack, $encoding ); |
|
669 | 669 | } |
670 | 670 | |
671 | - public static function mb_strripos($haystack, $needle, $offset = 0, $encoding = null) |
|
671 | + public static function mb_strripos( $haystack, $needle, $offset = 0, $encoding = null ) |
|
672 | 672 | { |
673 | - $haystack = self::mb_convert_case($haystack, self::MB_CASE_FOLD, $encoding); |
|
674 | - $needle = self::mb_convert_case($needle, self::MB_CASE_FOLD, $encoding); |
|
673 | + $haystack = self::mb_convert_case( $haystack, self::MB_CASE_FOLD, $encoding ); |
|
674 | + $needle = self::mb_convert_case( $needle, self::MB_CASE_FOLD, $encoding ); |
|
675 | 675 | |
676 | - return self::mb_strrpos($haystack, $needle, $offset, $encoding); |
|
676 | + return self::mb_strrpos( $haystack, $needle, $offset, $encoding ); |
|
677 | 677 | } |
678 | 678 | |
679 | - public static function mb_strstr($haystack, $needle, $part = false, $encoding = null) |
|
679 | + public static function mb_strstr( $haystack, $needle, $part = false, $encoding = null ) |
|
680 | 680 | { |
681 | - $pos = strpos($haystack, $needle); |
|
682 | - if (false === $pos) { |
|
681 | + $pos = strpos( $haystack, $needle ); |
|
682 | + if ( false === $pos ) { |
|
683 | 683 | return false; |
684 | 684 | } |
685 | - if ($part) { |
|
686 | - return substr($haystack, 0, $pos); |
|
685 | + if ( $part ) { |
|
686 | + return substr( $haystack, 0, $pos ); |
|
687 | 687 | } |
688 | 688 | |
689 | - return substr($haystack, $pos); |
|
689 | + return substr( $haystack, $pos ); |
|
690 | 690 | } |
691 | 691 | |
692 | - public static function mb_get_info($type = 'all') |
|
692 | + public static function mb_get_info( $type = 'all' ) |
|
693 | 693 | { |
694 | 694 | $info = [ |
695 | 695 | 'internal_encoding' => self::$internalEncoding, |
@@ -708,160 +708,160 @@ discard block |
||
708 | 708 | 'strict_detection' => 'Off', |
709 | 709 | ]; |
710 | 710 | |
711 | - if ('all' === $type) { |
|
711 | + if ( 'all' === $type ) { |
|
712 | 712 | return $info; |
713 | 713 | } |
714 | - if (isset($info[$type])) { |
|
715 | - return $info[$type]; |
|
714 | + if ( isset( $info[ $type ] ) ) { |
|
715 | + return $info[ $type ]; |
|
716 | 716 | } |
717 | 717 | |
718 | 718 | return false; |
719 | 719 | } |
720 | 720 | |
721 | - public static function mb_http_input($type = '') |
|
721 | + public static function mb_http_input( $type = '' ) |
|
722 | 722 | { |
723 | 723 | return false; |
724 | 724 | } |
725 | 725 | |
726 | - public static function mb_http_output($encoding = null) |
|
726 | + public static function mb_http_output( $encoding = null ) |
|
727 | 727 | { |
728 | 728 | return null !== $encoding ? 'pass' === $encoding : 'pass'; |
729 | 729 | } |
730 | 730 | |
731 | - public static function mb_strwidth($s, $encoding = null) |
|
731 | + public static function mb_strwidth( $s, $encoding = null ) |
|
732 | 732 | { |
733 | - $encoding = self::getEncoding($encoding); |
|
733 | + $encoding = self::getEncoding( $encoding ); |
|
734 | 734 | |
735 | - if ('UTF-8' !== $encoding) { |
|
736 | - $s = \iconv($encoding, 'UTF-8//IGNORE', $s); |
|
735 | + if ( 'UTF-8' !== $encoding ) { |
|
736 | + $s = \iconv( $encoding, 'UTF-8//IGNORE', $s ); |
|
737 | 737 | } |
738 | 738 | |
739 | - $s = preg_replace('/[\x{1100}-\x{115F}\x{2329}\x{232A}\x{2E80}-\x{303E}\x{3040}-\x{A4CF}\x{AC00}-\x{D7A3}\x{F900}-\x{FAFF}\x{FE10}-\x{FE19}\x{FE30}-\x{FE6F}\x{FF00}-\x{FF60}\x{FFE0}-\x{FFE6}\x{20000}-\x{2FFFD}\x{30000}-\x{3FFFD}]/u', '', $s, -1, $wide); |
|
739 | + $s = preg_replace( '/[\x{1100}-\x{115F}\x{2329}\x{232A}\x{2E80}-\x{303E}\x{3040}-\x{A4CF}\x{AC00}-\x{D7A3}\x{F900}-\x{FAFF}\x{FE10}-\x{FE19}\x{FE30}-\x{FE6F}\x{FF00}-\x{FF60}\x{FFE0}-\x{FFE6}\x{20000}-\x{2FFFD}\x{30000}-\x{3FFFD}]/u', '', $s, -1, $wide ); |
|
740 | 740 | |
741 | - return ($wide << 1) + \iconv_strlen($s, 'UTF-8'); |
|
741 | + return ( $wide << 1 ) + \iconv_strlen( $s, 'UTF-8' ); |
|
742 | 742 | } |
743 | 743 | |
744 | - public static function mb_substr_count($haystack, $needle, $encoding = null) |
|
744 | + public static function mb_substr_count( $haystack, $needle, $encoding = null ) |
|
745 | 745 | { |
746 | - return substr_count($haystack, $needle); |
|
746 | + return substr_count( $haystack, $needle ); |
|
747 | 747 | } |
748 | 748 | |
749 | - public static function mb_output_handler($contents, $status) |
|
749 | + public static function mb_output_handler( $contents, $status ) |
|
750 | 750 | { |
751 | 751 | return $contents; |
752 | 752 | } |
753 | 753 | |
754 | - public static function mb_chr($code, $encoding = null) |
|
754 | + public static function mb_chr( $code, $encoding = null ) |
|
755 | 755 | { |
756 | - if (0x80 > $code %= 0x200000) { |
|
757 | - $s = \chr($code); |
|
758 | - } elseif (0x800 > $code) { |
|
759 | - $s = \chr(0xC0 | $code >> 6).\chr(0x80 | $code & 0x3F); |
|
760 | - } elseif (0x10000 > $code) { |
|
761 | - $s = \chr(0xE0 | $code >> 12).\chr(0x80 | $code >> 6 & 0x3F).\chr(0x80 | $code & 0x3F); |
|
756 | + if ( 0x80 > $code %= 0x200000 ) { |
|
757 | + $s = \chr( $code ); |
|
758 | + } elseif ( 0x800 > $code ) { |
|
759 | + $s = \chr( 0xC0 | $code >> 6 ) . \chr( 0x80 | $code & 0x3F ); |
|
760 | + } elseif ( 0x10000 > $code ) { |
|
761 | + $s = \chr( 0xE0 | $code >> 12 ) . \chr( 0x80 | $code >> 6 & 0x3F ) . \chr( 0x80 | $code & 0x3F ); |
|
762 | 762 | } else { |
763 | - $s = \chr(0xF0 | $code >> 18).\chr(0x80 | $code >> 12 & 0x3F).\chr(0x80 | $code >> 6 & 0x3F).\chr(0x80 | $code & 0x3F); |
|
763 | + $s = \chr( 0xF0 | $code >> 18 ) . \chr( 0x80 | $code >> 12 & 0x3F ) . \chr( 0x80 | $code >> 6 & 0x3F ) . \chr( 0x80 | $code & 0x3F ); |
|
764 | 764 | } |
765 | 765 | |
766 | - if ('UTF-8' !== $encoding = self::getEncoding($encoding)) { |
|
767 | - $s = mb_convert_encoding($s, $encoding, 'UTF-8'); |
|
766 | + if ( 'UTF-8' !== $encoding = self::getEncoding( $encoding ) ) { |
|
767 | + $s = mb_convert_encoding( $s, $encoding, 'UTF-8' ); |
|
768 | 768 | } |
769 | 769 | |
770 | 770 | return $s; |
771 | 771 | } |
772 | 772 | |
773 | - public static function mb_ord($s, $encoding = null) |
|
773 | + public static function mb_ord( $s, $encoding = null ) |
|
774 | 774 | { |
775 | - if ('UTF-8' !== $encoding = self::getEncoding($encoding)) { |
|
776 | - $s = mb_convert_encoding($s, 'UTF-8', $encoding); |
|
775 | + if ( 'UTF-8' !== $encoding = self::getEncoding( $encoding ) ) { |
|
776 | + $s = mb_convert_encoding( $s, 'UTF-8', $encoding ); |
|
777 | 777 | } |
778 | 778 | |
779 | - if (1 === \strlen($s)) { |
|
780 | - return \ord($s); |
|
779 | + if ( 1 === \strlen( $s ) ) { |
|
780 | + return \ord( $s ); |
|
781 | 781 | } |
782 | 782 | |
783 | - $code = ($s = unpack('C*', substr($s, 0, 4))) ? $s[1] : 0; |
|
784 | - if (0xF0 <= $code) { |
|
785 | - return (($code - 0xF0) << 18) + (($s[2] - 0x80) << 12) + (($s[3] - 0x80) << 6) + $s[4] - 0x80; |
|
783 | + $code = ( $s = unpack( 'C*', substr( $s, 0, 4 ) ) ) ? $s[ 1 ] : 0; |
|
784 | + if ( 0xF0 <= $code ) { |
|
785 | + return ( ( $code - 0xF0 ) << 18 ) + ( ( $s[ 2 ] - 0x80 ) << 12 ) + ( ( $s[ 3 ] - 0x80 ) << 6 ) + $s[ 4 ] - 0x80; |
|
786 | 786 | } |
787 | - if (0xE0 <= $code) { |
|
788 | - return (($code - 0xE0) << 12) + (($s[2] - 0x80) << 6) + $s[3] - 0x80; |
|
787 | + if ( 0xE0 <= $code ) { |
|
788 | + return ( ( $code - 0xE0 ) << 12 ) + ( ( $s[ 2 ] - 0x80 ) << 6 ) + $s[ 3 ] - 0x80; |
|
789 | 789 | } |
790 | - if (0xC0 <= $code) { |
|
791 | - return (($code - 0xC0) << 6) + $s[2] - 0x80; |
|
790 | + if ( 0xC0 <= $code ) { |
|
791 | + return ( ( $code - 0xC0 ) << 6 ) + $s[ 2 ] - 0x80; |
|
792 | 792 | } |
793 | 793 | |
794 | 794 | return $code; |
795 | 795 | } |
796 | 796 | |
797 | - private static function getSubpart($pos, $part, $haystack, $encoding) |
|
797 | + private static function getSubpart( $pos, $part, $haystack, $encoding ) |
|
798 | 798 | { |
799 | - if (false === $pos) { |
|
799 | + if ( false === $pos ) { |
|
800 | 800 | return false; |
801 | 801 | } |
802 | - if ($part) { |
|
803 | - return self::mb_substr($haystack, 0, $pos, $encoding); |
|
802 | + if ( $part ) { |
|
803 | + return self::mb_substr( $haystack, 0, $pos, $encoding ); |
|
804 | 804 | } |
805 | 805 | |
806 | - return self::mb_substr($haystack, $pos, null, $encoding); |
|
806 | + return self::mb_substr( $haystack, $pos, null, $encoding ); |
|
807 | 807 | } |
808 | 808 | |
809 | - private static function html_encoding_callback(array $m) |
|
809 | + private static function html_encoding_callback( array $m ) |
|
810 | 810 | { |
811 | 811 | $i = 1; |
812 | 812 | $entities = ''; |
813 | - $m = unpack('C*', htmlentities($m[0], \ENT_COMPAT, 'UTF-8')); |
|
813 | + $m = unpack( 'C*', htmlentities( $m[ 0 ], \ENT_COMPAT, 'UTF-8' ) ); |
|
814 | 814 | |
815 | - while (isset($m[$i])) { |
|
816 | - if (0x80 > $m[$i]) { |
|
817 | - $entities .= \chr($m[$i++]); |
|
815 | + while ( isset( $m[ $i ] ) ) { |
|
816 | + if ( 0x80 > $m[ $i ] ) { |
|
817 | + $entities .= \chr( $m[ $i++ ] ); |
|
818 | 818 | continue; |
819 | 819 | } |
820 | - if (0xF0 <= $m[$i]) { |
|
821 | - $c = (($m[$i++] - 0xF0) << 18) + (($m[$i++] - 0x80) << 12) + (($m[$i++] - 0x80) << 6) + $m[$i++] - 0x80; |
|
822 | - } elseif (0xE0 <= $m[$i]) { |
|
823 | - $c = (($m[$i++] - 0xE0) << 12) + (($m[$i++] - 0x80) << 6) + $m[$i++] - 0x80; |
|
820 | + if ( 0xF0 <= $m[ $i ] ) { |
|
821 | + $c = ( ( $m[ $i++ ] - 0xF0 ) << 18 ) + ( ( $m[ $i++ ] - 0x80 ) << 12 ) + ( ( $m[ $i++ ] - 0x80 ) << 6 ) + $m[ $i++ ] - 0x80; |
|
822 | + } elseif ( 0xE0 <= $m[ $i ] ) { |
|
823 | + $c = ( ( $m[ $i++ ] - 0xE0 ) << 12 ) + ( ( $m[ $i++ ] - 0x80 ) << 6 ) + $m[ $i++ ] - 0x80; |
|
824 | 824 | } else { |
825 | - $c = (($m[$i++] - 0xC0) << 6) + $m[$i++] - 0x80; |
|
825 | + $c = ( ( $m[ $i++ ] - 0xC0 ) << 6 ) + $m[ $i++ ] - 0x80; |
|
826 | 826 | } |
827 | 827 | |
828 | - $entities .= '&#'.$c.';'; |
|
828 | + $entities .= '&#' . $c . ';'; |
|
829 | 829 | } |
830 | 830 | |
831 | 831 | return $entities; |
832 | 832 | } |
833 | 833 | |
834 | - private static function title_case(array $s) |
|
834 | + private static function title_case( array $s ) |
|
835 | 835 | { |
836 | - return self::mb_convert_case($s[1], \MB_CASE_UPPER, 'UTF-8').self::mb_convert_case($s[2], \MB_CASE_LOWER, 'UTF-8'); |
|
836 | + return self::mb_convert_case( $s[ 1 ], \MB_CASE_UPPER, 'UTF-8' ) . self::mb_convert_case( $s[ 2 ], \MB_CASE_LOWER, 'UTF-8' ); |
|
837 | 837 | } |
838 | 838 | |
839 | - private static function getData($file) |
|
839 | + private static function getData( $file ) |
|
840 | 840 | { |
841 | - if (file_exists($file = __DIR__.'/Resources/unidata/'.$file.'.php')) { |
|
841 | + if ( file_exists( $file = __DIR__ . '/Resources/unidata/' . $file . '.php' ) ) { |
|
842 | 842 | return require $file; |
843 | 843 | } |
844 | 844 | |
845 | 845 | return false; |
846 | 846 | } |
847 | 847 | |
848 | - private static function getEncoding($encoding) |
|
848 | + private static function getEncoding( $encoding ) |
|
849 | 849 | { |
850 | - if (null === $encoding) { |
|
850 | + if ( null === $encoding ) { |
|
851 | 851 | return self::$internalEncoding; |
852 | 852 | } |
853 | 853 | |
854 | - if ('UTF-8' === $encoding) { |
|
854 | + if ( 'UTF-8' === $encoding ) { |
|
855 | 855 | return 'UTF-8'; |
856 | 856 | } |
857 | 857 | |
858 | - $encoding = strtoupper($encoding); |
|
858 | + $encoding = strtoupper( $encoding ); |
|
859 | 859 | |
860 | - if ('8BIT' === $encoding || 'BINARY' === $encoding) { |
|
860 | + if ( '8BIT' === $encoding || 'BINARY' === $encoding ) { |
|
861 | 861 | return 'CP850'; |
862 | 862 | } |
863 | 863 | |
864 | - if ('UTF8' === $encoding) { |
|
864 | + if ( 'UTF8' === $encoding ) { |
|
865 | 865 | return 'UTF-8'; |
866 | 866 | } |
867 | 867 |
@@ -11,133 +11,133 @@ |
||
11 | 11 | |
12 | 12 | use Symfony\Polyfill\Mbstring as p; |
13 | 13 | |
14 | -if (!function_exists('mb_convert_encoding')) { |
|
15 | - function mb_convert_encoding(array|string|null $string, ?string $to_encoding, array|string|null $from_encoding = null): array|string|false { return p\Mbstring::mb_convert_encoding($string ?? '', (string) $to_encoding, $from_encoding); } |
|
14 | +if ( ! function_exists( 'mb_convert_encoding' ) ) { |
|
15 | + function mb_convert_encoding( array | string | null $string, ?string $to_encoding, array | string | null $from_encoding = null ): array | string | false { return p\Mbstring::mb_convert_encoding( $string ?? '', (string)$to_encoding, $from_encoding ); } |
|
16 | 16 | } |
17 | -if (!function_exists('mb_decode_mimeheader')) { |
|
18 | - function mb_decode_mimeheader(?string $string): string { return p\Mbstring::mb_decode_mimeheader((string) $string); } |
|
17 | +if ( ! function_exists( 'mb_decode_mimeheader' ) ) { |
|
18 | + function mb_decode_mimeheader( ?string $string ): string { return p\Mbstring::mb_decode_mimeheader( (string)$string ); } |
|
19 | 19 | } |
20 | -if (!function_exists('mb_encode_mimeheader')) { |
|
21 | - function mb_encode_mimeheader(?string $string, ?string $charset = null, ?string $transfer_encoding = null, ?string $newline = "\r\n", ?int $indent = 0): string { return p\Mbstring::mb_encode_mimeheader((string) $string, $charset, $transfer_encoding, (string) $newline, (int) $indent); } |
|
20 | +if ( ! function_exists( 'mb_encode_mimeheader' ) ) { |
|
21 | + function mb_encode_mimeheader( ?string $string, ?string $charset = null, ?string $transfer_encoding = null, ?string $newline = "\r\n", ?int $indent = 0 ): string { return p\Mbstring::mb_encode_mimeheader( (string)$string, $charset, $transfer_encoding, (string)$newline, (int)$indent ); } |
|
22 | 22 | } |
23 | -if (!function_exists('mb_decode_numericentity')) { |
|
24 | - function mb_decode_numericentity(?string $string, array $map, ?string $encoding = null): string { return p\Mbstring::mb_decode_numericentity((string) $string, $map, $encoding); } |
|
23 | +if ( ! function_exists( 'mb_decode_numericentity' ) ) { |
|
24 | + function mb_decode_numericentity( ?string $string, array $map, ?string $encoding = null ): string { return p\Mbstring::mb_decode_numericentity( (string)$string, $map, $encoding ); } |
|
25 | 25 | } |
26 | -if (!function_exists('mb_encode_numericentity')) { |
|
27 | - function mb_encode_numericentity(?string $string, array $map, ?string $encoding = null, ?bool $hex = false): string { return p\Mbstring::mb_encode_numericentity((string) $string, $map, $encoding, (bool) $hex); } |
|
26 | +if ( ! function_exists( 'mb_encode_numericentity' ) ) { |
|
27 | + function mb_encode_numericentity( ?string $string, array $map, ?string $encoding = null, ?bool $hex = false ): string { return p\Mbstring::mb_encode_numericentity( (string)$string, $map, $encoding, (bool)$hex ); } |
|
28 | 28 | } |
29 | -if (!function_exists('mb_convert_case')) { |
|
30 | - function mb_convert_case(?string $string, ?int $mode, ?string $encoding = null): string { return p\Mbstring::mb_convert_case((string) $string, (int) $mode, $encoding); } |
|
29 | +if ( ! function_exists( 'mb_convert_case' ) ) { |
|
30 | + function mb_convert_case( ?string $string, ?int $mode, ?string $encoding = null ): string { return p\Mbstring::mb_convert_case( (string)$string, (int)$mode, $encoding ); } |
|
31 | 31 | } |
32 | -if (!function_exists('mb_internal_encoding')) { |
|
33 | - function mb_internal_encoding(?string $encoding = null): string|bool { return p\Mbstring::mb_internal_encoding($encoding); } |
|
32 | +if ( ! function_exists( 'mb_internal_encoding' ) ) { |
|
33 | + function mb_internal_encoding( ?string $encoding = null ): string | bool { return p\Mbstring::mb_internal_encoding( $encoding ); } |
|
34 | 34 | } |
35 | -if (!function_exists('mb_language')) { |
|
36 | - function mb_language(?string $language = null): string|bool { return p\Mbstring::mb_language($language); } |
|
35 | +if ( ! function_exists( 'mb_language' ) ) { |
|
36 | + function mb_language( ?string $language = null ): string | bool { return p\Mbstring::mb_language( $language ); } |
|
37 | 37 | } |
38 | -if (!function_exists('mb_list_encodings')) { |
|
38 | +if ( ! function_exists( 'mb_list_encodings' ) ) { |
|
39 | 39 | function mb_list_encodings(): array { return p\Mbstring::mb_list_encodings(); } |
40 | 40 | } |
41 | -if (!function_exists('mb_encoding_aliases')) { |
|
42 | - function mb_encoding_aliases(?string $encoding): array { return p\Mbstring::mb_encoding_aliases((string) $encoding); } |
|
41 | +if ( ! function_exists( 'mb_encoding_aliases' ) ) { |
|
42 | + function mb_encoding_aliases( ?string $encoding ): array { return p\Mbstring::mb_encoding_aliases( (string)$encoding ); } |
|
43 | 43 | } |
44 | -if (!function_exists('mb_check_encoding')) { |
|
45 | - function mb_check_encoding(array|string|null $value = null, ?string $encoding = null): bool { return p\Mbstring::mb_check_encoding($value, $encoding); } |
|
44 | +if ( ! function_exists( 'mb_check_encoding' ) ) { |
|
45 | + function mb_check_encoding( array | string | null $value = null, ?string $encoding = null ): bool { return p\Mbstring::mb_check_encoding( $value, $encoding ); } |
|
46 | 46 | } |
47 | -if (!function_exists('mb_detect_encoding')) { |
|
48 | - function mb_detect_encoding(?string $string, array|string|null $encodings = null, ?bool $strict = false): string|false { return p\Mbstring::mb_detect_encoding((string) $string, $encodings, (bool) $strict); } |
|
47 | +if ( ! function_exists( 'mb_detect_encoding' ) ) { |
|
48 | + function mb_detect_encoding( ?string $string, array | string | null $encodings = null, ?bool $strict = false ): string | false { return p\Mbstring::mb_detect_encoding( (string)$string, $encodings, (bool)$strict ); } |
|
49 | 49 | } |
50 | -if (!function_exists('mb_detect_order')) { |
|
51 | - function mb_detect_order(array|string|null $encoding = null): array|bool { return p\Mbstring::mb_detect_order($encoding); } |
|
50 | +if ( ! function_exists( 'mb_detect_order' ) ) { |
|
51 | + function mb_detect_order( array | string | null $encoding = null ): array | bool { return p\Mbstring::mb_detect_order( $encoding ); } |
|
52 | 52 | } |
53 | -if (!function_exists('mb_parse_str')) { |
|
54 | - function mb_parse_str(?string $string, &$result = []): bool { parse_str((string) $string, $result); return (bool) $result; } |
|
53 | +if ( ! function_exists( 'mb_parse_str' ) ) { |
|
54 | + function mb_parse_str( ?string $string, &$result = [ ] ): bool { parse_str( (string)$string, $result ); return (bool)$result; } |
|
55 | 55 | } |
56 | -if (!function_exists('mb_strlen')) { |
|
57 | - function mb_strlen(?string $string, ?string $encoding = null): int { return p\Mbstring::mb_strlen((string) $string, $encoding); } |
|
56 | +if ( ! function_exists( 'mb_strlen' ) ) { |
|
57 | + function mb_strlen( ?string $string, ?string $encoding = null ): int { return p\Mbstring::mb_strlen( (string)$string, $encoding ); } |
|
58 | 58 | } |
59 | -if (!function_exists('mb_strpos')) { |
|
60 | - function mb_strpos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_strpos((string) $haystack, (string) $needle, (int) $offset, $encoding); } |
|
59 | +if ( ! function_exists( 'mb_strpos' ) ) { |
|
60 | + function mb_strpos( ?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null ): int | false { return p\Mbstring::mb_strpos( (string)$haystack, (string)$needle, (int)$offset, $encoding ); } |
|
61 | 61 | } |
62 | -if (!function_exists('mb_strtolower')) { |
|
63 | - function mb_strtolower(?string $string, ?string $encoding = null): string { return p\Mbstring::mb_strtolower((string) $string, $encoding); } |
|
62 | +if ( ! function_exists( 'mb_strtolower' ) ) { |
|
63 | + function mb_strtolower( ?string $string, ?string $encoding = null ): string { return p\Mbstring::mb_strtolower( (string)$string, $encoding ); } |
|
64 | 64 | } |
65 | -if (!function_exists('mb_strtoupper')) { |
|
66 | - function mb_strtoupper(?string $string, ?string $encoding = null): string { return p\Mbstring::mb_strtoupper((string) $string, $encoding); } |
|
65 | +if ( ! function_exists( 'mb_strtoupper' ) ) { |
|
66 | + function mb_strtoupper( ?string $string, ?string $encoding = null ): string { return p\Mbstring::mb_strtoupper( (string)$string, $encoding ); } |
|
67 | 67 | } |
68 | -if (!function_exists('mb_substitute_character')) { |
|
69 | - function mb_substitute_character(string|int|null $substitute_character = null): string|int|bool { return p\Mbstring::mb_substitute_character($substitute_character); } |
|
68 | +if ( ! function_exists( 'mb_substitute_character' ) ) { |
|
69 | + function mb_substitute_character( string | int | null $substitute_character = null ): string | int | bool { return p\Mbstring::mb_substitute_character( $substitute_character ); } |
|
70 | 70 | } |
71 | -if (!function_exists('mb_substr')) { |
|
72 | - function mb_substr(?string $string, ?int $start, ?int $length = null, ?string $encoding = null): string { return p\Mbstring::mb_substr((string) $string, (int) $start, $length, $encoding); } |
|
71 | +if ( ! function_exists( 'mb_substr' ) ) { |
|
72 | + function mb_substr( ?string $string, ?int $start, ?int $length = null, ?string $encoding = null ): string { return p\Mbstring::mb_substr( (string)$string, (int)$start, $length, $encoding ); } |
|
73 | 73 | } |
74 | -if (!function_exists('mb_stripos')) { |
|
75 | - function mb_stripos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_stripos((string) $haystack, (string) $needle, (int) $offset, $encoding); } |
|
74 | +if ( ! function_exists( 'mb_stripos' ) ) { |
|
75 | + function mb_stripos( ?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null ): int | false { return p\Mbstring::mb_stripos( (string)$haystack, (string)$needle, (int)$offset, $encoding ); } |
|
76 | 76 | } |
77 | -if (!function_exists('mb_stristr')) { |
|
78 | - function mb_stristr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_stristr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); } |
|
77 | +if ( ! function_exists( 'mb_stristr' ) ) { |
|
78 | + function mb_stristr( ?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null ): string | false { return p\Mbstring::mb_stristr( (string)$haystack, (string)$needle, (bool)$before_needle, $encoding ); } |
|
79 | 79 | } |
80 | -if (!function_exists('mb_strrchr')) { |
|
81 | - function mb_strrchr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_strrchr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); } |
|
80 | +if ( ! function_exists( 'mb_strrchr' ) ) { |
|
81 | + function mb_strrchr( ?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null ): string | false { return p\Mbstring::mb_strrchr( (string)$haystack, (string)$needle, (bool)$before_needle, $encoding ); } |
|
82 | 82 | } |
83 | -if (!function_exists('mb_strrichr')) { |
|
84 | - function mb_strrichr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_strrichr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); } |
|
83 | +if ( ! function_exists( 'mb_strrichr' ) ) { |
|
84 | + function mb_strrichr( ?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null ): string | false { return p\Mbstring::mb_strrichr( (string)$haystack, (string)$needle, (bool)$before_needle, $encoding ); } |
|
85 | 85 | } |
86 | -if (!function_exists('mb_strripos')) { |
|
87 | - function mb_strripos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_strripos((string) $haystack, (string) $needle, (int) $offset, $encoding); } |
|
86 | +if ( ! function_exists( 'mb_strripos' ) ) { |
|
87 | + function mb_strripos( ?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null ): int | false { return p\Mbstring::mb_strripos( (string)$haystack, (string)$needle, (int)$offset, $encoding ); } |
|
88 | 88 | } |
89 | -if (!function_exists('mb_strrpos')) { |
|
90 | - function mb_strrpos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_strrpos((string) $haystack, (string) $needle, (int) $offset, $encoding); } |
|
89 | +if ( ! function_exists( 'mb_strrpos' ) ) { |
|
90 | + function mb_strrpos( ?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null ): int | false { return p\Mbstring::mb_strrpos( (string)$haystack, (string)$needle, (int)$offset, $encoding ); } |
|
91 | 91 | } |
92 | -if (!function_exists('mb_strstr')) { |
|
93 | - function mb_strstr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_strstr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); } |
|
92 | +if ( ! function_exists( 'mb_strstr' ) ) { |
|
93 | + function mb_strstr( ?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null ): string | false { return p\Mbstring::mb_strstr( (string)$haystack, (string)$needle, (bool)$before_needle, $encoding ); } |
|
94 | 94 | } |
95 | -if (!function_exists('mb_get_info')) { |
|
96 | - function mb_get_info(?string $type = 'all'): array|string|int|false { return p\Mbstring::mb_get_info((string) $type); } |
|
95 | +if ( ! function_exists( 'mb_get_info' ) ) { |
|
96 | + function mb_get_info( ?string $type = 'all' ): array | string | int | false { return p\Mbstring::mb_get_info( (string)$type ); } |
|
97 | 97 | } |
98 | -if (!function_exists('mb_http_output')) { |
|
99 | - function mb_http_output(?string $encoding = null): string|bool { return p\Mbstring::mb_http_output($encoding); } |
|
98 | +if ( ! function_exists( 'mb_http_output' ) ) { |
|
99 | + function mb_http_output( ?string $encoding = null ): string | bool { return p\Mbstring::mb_http_output( $encoding ); } |
|
100 | 100 | } |
101 | -if (!function_exists('mb_strwidth')) { |
|
102 | - function mb_strwidth(?string $string, ?string $encoding = null): int { return p\Mbstring::mb_strwidth((string) $string, $encoding); } |
|
101 | +if ( ! function_exists( 'mb_strwidth' ) ) { |
|
102 | + function mb_strwidth( ?string $string, ?string $encoding = null ): int { return p\Mbstring::mb_strwidth( (string)$string, $encoding ); } |
|
103 | 103 | } |
104 | -if (!function_exists('mb_substr_count')) { |
|
105 | - function mb_substr_count(?string $haystack, ?string $needle, ?string $encoding = null): int { return p\Mbstring::mb_substr_count((string) $haystack, (string) $needle, $encoding); } |
|
104 | +if ( ! function_exists( 'mb_substr_count' ) ) { |
|
105 | + function mb_substr_count( ?string $haystack, ?string $needle, ?string $encoding = null ): int { return p\Mbstring::mb_substr_count( (string)$haystack, (string)$needle, $encoding ); } |
|
106 | 106 | } |
107 | -if (!function_exists('mb_output_handler')) { |
|
108 | - function mb_output_handler(?string $string, ?int $status): string { return p\Mbstring::mb_output_handler((string) $string, (int) $status); } |
|
107 | +if ( ! function_exists( 'mb_output_handler' ) ) { |
|
108 | + function mb_output_handler( ?string $string, ?int $status ): string { return p\Mbstring::mb_output_handler( (string)$string, (int)$status ); } |
|
109 | 109 | } |
110 | -if (!function_exists('mb_http_input')) { |
|
111 | - function mb_http_input(?string $type = null): array|string|false { return p\Mbstring::mb_http_input($type); } |
|
110 | +if ( ! function_exists( 'mb_http_input' ) ) { |
|
111 | + function mb_http_input( ?string $type = null ): array | string | false { return p\Mbstring::mb_http_input( $type ); } |
|
112 | 112 | } |
113 | 113 | |
114 | -if (!function_exists('mb_convert_variables')) { |
|
115 | - function mb_convert_variables(?string $to_encoding, array|string|null $from_encoding, mixed &$var, mixed &...$vars): string|false { return p\Mbstring::mb_convert_variables((string) $to_encoding, $from_encoding ?? '', $var, ...$vars); } |
|
114 | +if ( ! function_exists( 'mb_convert_variables' ) ) { |
|
115 | + function mb_convert_variables( ?string $to_encoding, array | string | null $from_encoding, mixed &$var, mixed &...$vars ): string | false { return p\Mbstring::mb_convert_variables( (string)$to_encoding, $from_encoding ?? '', $var, ...$vars ); } |
|
116 | 116 | } |
117 | 117 | |
118 | -if (!function_exists('mb_ord')) { |
|
119 | - function mb_ord(?string $string, ?string $encoding = null): int|false { return p\Mbstring::mb_ord((string) $string, $encoding); } |
|
118 | +if ( ! function_exists( 'mb_ord' ) ) { |
|
119 | + function mb_ord( ?string $string, ?string $encoding = null ): int | false { return p\Mbstring::mb_ord( (string)$string, $encoding ); } |
|
120 | 120 | } |
121 | -if (!function_exists('mb_chr')) { |
|
122 | - function mb_chr(?int $codepoint, ?string $encoding = null): string|false { return p\Mbstring::mb_chr((int) $codepoint, $encoding); } |
|
121 | +if ( ! function_exists( 'mb_chr' ) ) { |
|
122 | + function mb_chr( ?int $codepoint, ?string $encoding = null ): string | false { return p\Mbstring::mb_chr( (int)$codepoint, $encoding ); } |
|
123 | 123 | } |
124 | -if (!function_exists('mb_scrub')) { |
|
125 | - function mb_scrub(?string $string, ?string $encoding = null): string { $encoding ??= mb_internal_encoding(); return mb_convert_encoding((string) $string, $encoding, $encoding); } |
|
124 | +if ( ! function_exists( 'mb_scrub' ) ) { |
|
125 | + function mb_scrub( ?string $string, ?string $encoding = null ): string { $encoding ??= mb_internal_encoding(); return mb_convert_encoding( (string)$string, $encoding, $encoding ); } |
|
126 | 126 | } |
127 | -if (!function_exists('mb_str_split')) { |
|
128 | - function mb_str_split(?string $string, ?int $length = 1, ?string $encoding = null): array { return p\Mbstring::mb_str_split((string) $string, (int) $length, $encoding); } |
|
127 | +if ( ! function_exists( 'mb_str_split' ) ) { |
|
128 | + function mb_str_split( ?string $string, ?int $length = 1, ?string $encoding = null ): array { return p\Mbstring::mb_str_split( (string)$string, (int)$length, $encoding ); } |
|
129 | 129 | } |
130 | 130 | |
131 | -if (extension_loaded('mbstring')) { |
|
131 | +if ( extension_loaded( 'mbstring' ) ) { |
|
132 | 132 | return; |
133 | 133 | } |
134 | 134 | |
135 | -if (!defined('MB_CASE_UPPER')) { |
|
136 | - define('MB_CASE_UPPER', 0); |
|
135 | +if ( ! defined( 'MB_CASE_UPPER' ) ) { |
|
136 | + define( 'MB_CASE_UPPER', 0 ); |
|
137 | 137 | } |
138 | -if (!defined('MB_CASE_LOWER')) { |
|
139 | - define('MB_CASE_LOWER', 1); |
|
138 | +if ( ! defined( 'MB_CASE_LOWER' ) ) { |
|
139 | + define( 'MB_CASE_LOWER', 1 ); |
|
140 | 140 | } |
141 | -if (!defined('MB_CASE_TITLE')) { |
|
142 | - define('MB_CASE_TITLE', 2); |
|
141 | +if ( ! defined( 'MB_CASE_TITLE' ) ) { |
|
142 | + define( 'MB_CASE_TITLE', 2 ); |
|
143 | 143 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -return array ( |
|
3 | +return array( |
|
4 | 4 | 'a' => 'A', |
5 | 5 | 'b' => 'B', |
6 | 6 | 'c' => 'C', |