diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index ea6822a..2020a5f 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -6,14 +6,14 @@ on: [pull_request] jobs: phpstan: name: PHPStan - runs-on: Ubuntu-20.04 + runs-on: Ubuntu-22.04 steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Cache PHPStan - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: .github/.cache/phpstan/ key: phpstan-${{ github.sha }} @@ -26,7 +26,7 @@ jobs: coverage: none - name: Download dependencies - uses: ramsey/composer-install@v2 + uses: ramsey/composer-install@v3 with: composer-options: --no-interaction --prefer-dist --optimize-autoloader @@ -40,7 +40,7 @@ jobs: name: PHP-CS-Fixer runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: PHP-CS-Fixer uses: docker://oskarstark/php-cs-fixer-ga with: @@ -48,13 +48,13 @@ jobs: psalm: name: Psalm - runs-on: Ubuntu-20.04 + runs-on: Ubuntu-22.04 steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Cache Psalm - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: .github/.cache/psalm/ key: psalm-${{ github.sha }} @@ -67,7 +67,7 @@ jobs: coverage: none - name: Download dependencies - uses: ramsey/composer-install@v1 + uses: ramsey/composer-install@v3 with: composer-options: --no-interaction --prefer-dist --optimize-autoloader diff --git a/DependencyInjection/TranslationExtension.php b/DependencyInjection/TranslationExtension.php index 1ba8fed..ede6351 100644 --- a/DependencyInjection/TranslationExtension.php +++ b/DependencyInjection/TranslationExtension.php @@ -16,9 +16,9 @@ use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; +use Symfony\Component\DependencyInjection\Extension\Extension; use Symfony\Component\DependencyInjection\Loader; use Symfony\Component\DependencyInjection\Reference; -use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\HttpKernel\Kernel; use Translation\Bundle\EventListener\AutoAddMissingTranslations; use Translation\Bundle\EventListener\EditInPlaceResponseListener; diff --git a/Tests/Functional/Controller/EditInPlaceTest.php b/Tests/Functional/Controller/EditInPlaceTest.php index 932af74..733a1e2 100644 --- a/Tests/Functional/Controller/EditInPlaceTest.php +++ b/Tests/Functional/Controller/EditInPlaceTest.php @@ -40,7 +40,7 @@ public function testActivatedTest(): void self::assertStringContainsString('', $response->getContent()); $dom = new \DOMDocument('1.0', 'utf-8'); - @$dom->loadHTML(mb_convert_encoding($response->getContent(), 'HTML-ENTITIES', 'UTF-8')); + @$dom->loadHTML(mb_encode_numericentity($response->getContent(), [0x80, 0x10FFFF, 0, ~0], 'UTF-8')); $xpath = new \DOMXPath($dom); // Check number of x-trans tags @@ -79,7 +79,7 @@ public function testIfUntranslatableLabelGetsDisabled(): void self::assertStringContainsString('', $response->getContent()); $dom = new \DOMDocument('1.0', 'utf-8'); - @$dom->loadHTML(mb_convert_encoding($response->getContent(), 'HTML-ENTITIES', 'UTF-8')); + @$dom->loadHTML(mb_encode_numericentity($response->getContent(), [0x80, 0x10FFFF, 0, ~0], 'UTF-8')); $xpath = new \DOMXPath($dom); // Check number of x-trans tags diff --git a/Twig/Visitor/DefaultApplyingNodeVisitor.php b/Twig/Visitor/DefaultApplyingNodeVisitor.php index 9c112a7..5be6d88 100644 --- a/Twig/Visitor/DefaultApplyingNodeVisitor.php +++ b/Twig/Visitor/DefaultApplyingNodeVisitor.php @@ -18,8 +18,11 @@ use Twig\Node\Expression\ConditionalExpression; use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\FilterExpression; +use Twig\Node\Expression\Ternary\ConditionalTernary; use Twig\Node\Node; +use Twig\Node\Nodes; use Twig\NodeVisitor\AbstractNodeVisitor; +use Twig\TwigFilter; /** * Applies the value of the "desc" filter if the "trans" filter has no @@ -93,22 +96,46 @@ public function doEnterNode(Node $node, Environment $env): Node $testNode->getNode('arguments')->setNode(0, new ArrayExpression([], $lineno)); // wrap the default node in a |replace filter - $defaultNode = new FilterExpression( - clone $node->getNode('arguments')->getNode(0), - new ConstantExpression('replace', $lineno), - new Node([ - clone $wrappingNode->getNode('arguments')->getNode(0), - ]), - $lineno + if (Environment::VERSION_ID >= 31500) { + $defaultNode = new FilterExpression( + clone $node->getNode('arguments')->getNode(0), + new TwigFilter('replace'), + new Nodes([ + clone $wrappingNode->getNode('arguments')->getNode(0), + ]), + $lineno + ); + } else { + $defaultNode = new FilterExpression( + clone $node->getNode('arguments')->getNode(0), + new ConstantExpression('replace', $lineno), + new Node([ + clone $wrappingNode->getNode('arguments')->getNode(0), + ]), + $lineno + ); + } + } + + $expr = new EqualBinary($testNode, $transNode->getNode('node'), $wrappingNode->getTemplateLine()); + if (Environment::VERSION_ID >= 31700) { + $expr->setAttribute('operator', 'binary_=='); + + $condition = new ConditionalTernary( + $expr, + $defaultNode, + clone $wrappingNode, + $wrappingNode->getTemplateLine() + ); + } else { + $condition = new ConditionalExpression( + $expr, + $defaultNode, + clone $wrappingNode, + $wrappingNode->getTemplateLine() ); } - $condition = new ConditionalExpression( - new EqualBinary($testNode, $transNode->getNode('node'), $wrappingNode->getTemplateLine()), - $defaultNode, - clone $wrappingNode, - $wrappingNode->getTemplateLine() - ); $node->setNode('node', $condition); return $node; diff --git a/composer.json b/composer.json index e28adc8..3dd11d3 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "php-translation/symfony-storage": "^2.1", "php-translation/extractor": "^2.0", "nyholm/nsa": "^1.1", - "twig/twig": "^2.14.4 || ^3.3", + "twig/twig": "^3.3", "symfony/asset": "^5.3 || ^6.0 || ^7.0" }, "require-dev": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 0a4e149..5e2a761 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,38 +1,25 @@ - - - - - - - - - - - - - - - ./Tests - - - - - - ./ - - vendor - Tests - - - + + + + ./ + + + vendor + Tests + + + + + + + + + + + + + ./Tests + +