11
11
12
12
namespace Symfony \Component \Intl \Transliterator ;
13
13
14
- final class EmojiTransliterator extends \Transliterator
15
- {
16
- private const QUICK_CHECK = "\xE2\xE3\xF0" ;
14
+ if (\PHP_VERSION_ID >= 80200 ) {
15
+ final class EmojiTransliterator extends \Transliterator
16
+ {
17
+ use EmojiTransliteratorTrait;
18
+
19
+ private const QUICK_CHECK = "\xE2\xE3\xF0" ;
20
+
21
+ public readonly string $ id ;
22
+ }
23
+ } else {
24
+ final class EmojiTransliterator extends \Transliterator
25
+ {
26
+ use EmojiTransliteratorTrait;
27
+
28
+ private const QUICK_CHECK = "\xE2\xE3\xF0" ;
29
+ }
30
+ }
17
31
32
+ /**
33
+ * @internal
34
+ */
35
+ trait EmojiTransliteratorTrait
36
+ {
18
37
private array $ map ;
19
38
private \Transliterator $ transliterator ;
20
39
@@ -37,7 +56,14 @@ public static function create(string $id, int $direction = self::FORWARD): ?\Tra
37
56
static $ maps ;
38
57
39
58
// Create an instance of \Transliterator with a custom id; that's the only way
40
- $ instance = unserialize (sprintf ('O:%d:"%s":1:{s:2:"id";s:%d:"%s";} ' , \strlen (self ::class), self ::class, \strlen ($ id ), $ id ));
59
+ if (\PHP_VERSION_ID >= 80200 ) {
60
+ static $ newInstance ;
61
+ $ instance = ($ newInstance ??= (new \ReflectionClass (self ::class))->newInstanceWithoutConstructor (...))();
62
+ $ instance ->id = $ id ;
63
+ } else {
64
+ $ instance = unserialize (sprintf ('O:%d:"%s":1:{s:2:"id";s:%d:"%s";} ' , \strlen (self ::class), self ::class, \strlen ($ id ), $ id ));
65
+ }
66
+
41
67
$ instance ->map = $ maps [$ id ] ??= require \dirname (__DIR__ )."/Resources/data/transliterator/emoji/ {$ id }.php " ;
42
68
43
69
return $ instance ;
@@ -95,10 +121,6 @@ public function transliterate(string $string, int $start = 0, int $end = -1): st
95
121
return false ;
96
122
}
97
123
98
- if ($ cookie === $ result ) {
99
- return \strlen ($ string ) === strcspn ($ string , self ::QUICK_CHECK ) ? $ string : strtr ($ string , $ this ->map );
100
- }
101
-
102
124
$ parts = explode ($ cookie , $ result );
103
125
$ start = \strlen ($ parts [0 ]);
104
126
$ length = -\strlen ($ parts [1 ]) ?: null ;
0 commit comments