[Intl] Fix EmojiTransliterator on PHP 8.2
MODIFY
Tests/Transliterator/EmojiTransliteratorTest.php
Tests/Transliterator/EmojiTransliteratorTest.php
@@ -18,8 +18,15 @@ use Symfony\Component\Intl\Transliterator\EmojiTransliterator;
/**
* @requires extension intl
*/
-final class EmojiTransliteratorTest extends TestCase
+class EmojiTransliteratorTest extends TestCase
{
+ protected function setUp(): void
+ {
+ if (\PHP_VERSION_ID >= 80200 && !(new \ReflectionProperty(\Transliterator::class, 'id'))->isReadOnly()) {
+ $this->markTestSkipped('Waiting for https://github.com/php/php-src/pull/9167 to be merged');
+ }
+ }
+
public function provideTransliterateTests(): iterable
{
yield [

MODIFY
Transliterator/EmojiTransliterator.php
Transliterator/EmojiTransliterator.php
namespace Symfony\Component\Intl\Transliterator;
+if (\PHP_VERSION_ID >= 80200) {
final class EmojiTransliterator extends \Transliterator
{
+ use EmojiTransliteratorTrait;
+
+ private const QUICK_CHECK = "\xE2\xE3\xF0";
+
+ public readonly string $id;
+ }
+} else {
+ final class EmojiTransliterator extends \Transliterator
+ {
+ use EmojiTransliteratorTrait;
+
private const QUICK_CHECK = "\xE2\xE3\xF0";
+ }
+}
+/**
+ * @internal
+ */
+trait EmojiTransliteratorTrait
+{
private array $map;
private \Transliterator $transliterator;
@@ -37,7 +56,14 @@ final class EmojiTransliterator extends \Transliterator
static $maps;
// Create an instance of \Transliterator with a custom id; that's the only way
+ if (\PHP_VERSION_ID >= 80200) {
+ static $newInstance;
+ $instance = ($newInstance ??= (new \ReflectionClass(self::class))->newInstanceWithoutConstructor(...))();
+ $instance->id = $id;
+ } else {
$instance = unserialize(sprintf('O:%d:"%s":1:{s:2:"id";s:%d:"%s";}', \strlen(self::class), self::class, \strlen($id), $id));
+ }
+
$instance->map = $maps[$id] ??= require \dirname(__DIR__)."/Resources/data/transliterator/emoji/{$id}.php";
return $instance;
@@ -95,10 +121,6 @@ final class EmojiTransliterator extends \Transliterator
return false;
}
- if ($cookie === $result) {
- return \strlen($string) === strcspn($string, self::QUICK_CHECK) ? $string : strtr($string, $this->map);
- }
-
$parts = explode($cookie, $result);
$start = \strlen($parts[0]);
$length = -\strlen($parts[1]) ?: null;

[Intl] Fix EmojiTransliterator on PHP 8.2