Skip to content

Commit

Permalink
[TwigBridge] Fix compat with Twig v3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Feb 15, 2024
1 parent f44d074 commit e6427c2
Show file tree
Hide file tree
Showing 15 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"friendsofphp/proxy-manager-lts": "^1.0.2",
"doctrine/event-manager": "~1.0",
"doctrine/persistence": "^2|^3",
"twig/twig": "^2.13|~3.8.0",
"twig/twig": "^2.13|^3.0.4",
"psr/cache": "^1.0|^2.0",
"psr/container": "^1.1.1",
"psr/event-dispatcher": "^1.0",
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Bridge/Twig/Node/DumpNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@

namespace Symfony\Bridge\Twig\Node;

use Twig\Attribute\YieldReady;
use Twig\Compiler;
use Twig\Node\Node;

/**
* @author Julien Galenski <julien.galenski@gmail.com>
*/
#[YieldReady]
final class DumpNode extends Node
{
private $varPrefix;
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Bridge/Twig/Node/FormThemeNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@

namespace Symfony\Bridge\Twig\Node;

use Twig\Attribute\YieldReady;
use Symfony\Component\Form\FormRenderer;
use Twig\Compiler;
use Twig\Node\Node;

/**
* @author Fabien Potencier <fabien@symfony.com>
*/
#[YieldReady]
final class FormThemeNode extends Node
{
public function __construct(Node $form, Node $resources, int $lineno, ?string $tag = null, bool $only = false)
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Bridge/Twig/Node/StopwatchNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Bridge\Twig\Node;

use Twig\Attribute\YieldReady;
use Twig\Compiler;
use Twig\Node\Expression\AssignNameExpression;
use Twig\Node\Node;
Expand All @@ -20,6 +21,7 @@
*
* @author Wouter J <wouter@wouterj.nl>
*/
#[YieldReady]
final class StopwatchNode extends Node
{
public function __construct(Node $name, Node $body, AssignNameExpression $var, int $lineno = 0, ?string $tag = null)
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Bridge/Twig/Node/TransDefaultDomainNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@

namespace Symfony\Bridge\Twig\Node;

use Twig\Attribute\YieldReady;
use Twig\Compiler;
use Twig\Node\Expression\AbstractExpression;
use Twig\Node\Node;

/**
* @author Fabien Potencier <fabien@symfony.com>
*/
#[YieldReady]
final class TransDefaultDomainNode extends Node
{
public function __construct(AbstractExpression $expr, int $lineno = 0, ?string $tag = null)
Expand Down
5 changes: 4 additions & 1 deletion src/Symfony/Bridge/Twig/Node/TransNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Bridge\Twig\Node;

use Twig\Attribute\YieldReady;
use Twig\Compiler;
use Twig\Node\Expression\AbstractExpression;
use Twig\Node\Expression\ArrayExpression;
Expand All @@ -22,6 +23,7 @@
/**
* @author Fabien Potencier <fabien@symfony.com>
*/
#[YieldReady]
final class TransNode extends Node
{
public function __construct(Node $body, ?Node $domain = null, ?AbstractExpression $count = null, ?AbstractExpression $vars = null, ?AbstractExpression $locale = null, int $lineno = 0, ?string $tag = null)
Expand Down Expand Up @@ -53,9 +55,10 @@ public function compile(Compiler $compiler): void
$vars = null;
}
[$msg, $defaults] = $this->compileString($this->getNode('body'), $defaults, (bool) $vars);
$display = class_exists(YieldReady::class) ? 'yield' : 'echo';

$compiler
->write('echo $this->env->getExtension(\'Symfony\Bridge\Twig\Extension\TranslationExtension\')->trans(')
->write($display.' $this->env->getExtension(\'Symfony\Bridge\Twig\Extension\TranslationExtension\')->trans(')
->subcompile($msg)
;

Expand Down
4 changes: 3 additions & 1 deletion src/Symfony/Bridge/Twig/Tests/Node/TransNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Twig\Node\TransNode;
use Twig\Attribute\YieldReady;
use Twig\Compiler;
use Twig\Environment;
use Twig\Loader\LoaderInterface;
Expand All @@ -35,7 +36,8 @@ public function testCompileStrict()

$this->assertEquals(
sprintf(
'echo $this->env->getExtension(\'Symfony\Bridge\Twig\Extension\TranslationExtension\')->trans("trans %%var%%", array_merge(["%%var%%" => %s], %s), "messages");',
'%s $this->env->getExtension(\'Symfony\Bridge\Twig\Extension\TranslationExtension\')->trans("trans %%var%%", array_merge(["%%var%%" => %s], %s), "messages");',
class_exists(YieldReady::class) ? 'yield' : 'echo',
$this->getVariableGetterWithoutStrictCheck('var'),
$this->getVariableGetterWithStrictCheck('foo')
),
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"php": ">=7.2.5",
"symfony/polyfill-php80": "^1.16",
"symfony/translation-contracts": "^1.1|^2|^3",
"twig/twig": "^2.13|~3.8.0"
"twig/twig": "^2.13|^3.0.4"
},
"require-dev": {
"doctrine/annotations": "^1.12|^2",
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/FrameworkBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"symfony/property-info": "^4.4|^5.0|^6.0",
"symfony/web-link": "^4.4|^5.0|^6.0",
"phpdocumentor/reflection-docblock": "^3.0|^4.0|^5.0",
"twig/twig": "^2.10|~3.8.0"
"twig/twig": "^2.10|^3.0.4"
},
"conflict": {
"doctrine/annotations": "<1.13.1",
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/SecurityBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"symfony/twig-bridge": "^4.4|^5.0|^6.0",
"symfony/validator": "^4.4|^5.0|^6.0",
"symfony/yaml": "^4.4|^5.0|^6.0",
"twig/twig": "^2.13|~3.8.0"
"twig/twig": "^2.13|^3.0.4"
},
"conflict": {
"symfony/browser-kit": "<4.4",
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/TwigBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"symfony/http-kernel": "^5.0|^6.0",
"symfony/polyfill-ctype": "~1.8",
"symfony/polyfill-php80": "^1.16",
"twig/twig": "^2.13|~3.8.0"
"twig/twig": "^2.13|^3.0.4"
},
"require-dev": {
"symfony/asset": "^4.4|^5.0|^6.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/WebProfilerBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"symfony/polyfill-php80": "^1.16",
"symfony/routing": "^4.4|^5.0|^6.0",
"symfony/twig-bundle": "^4.4|^5.0|^6.0",
"twig/twig": "^2.13|~3.8.0"
"twig/twig": "^2.13|^3.0.4"
},
"require-dev": {
"symfony/browser-kit": "^4.4|^5.0|^6.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpKernel/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"symfony/translation": "^4.4|^5.0|^6.0",
"symfony/translation-contracts": "^1.1|^2|^3",
"psr/cache": "^1.0|^2.0|^3.0",
"twig/twig": "^2.13|~3.8.0"
"twig/twig": "^2.13|^3.0.4"
},
"provide": {
"psr/log-implementation": "1.0|2.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,7 @@ public function testThrowingCaster()
› twig source
}
%s%eTemplate.php:%d { …}
%s%eTemplate.php:%d { …}
%s%eTemplate.php:%d { …}
%A%eTemplate.php:%d { …}
%s%eTests%eDumper%eCliDumperTest.php:%d { …}
%A }
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/VarDumper/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"symfony/http-kernel": "^4.4|^5.0|^6.0",
"symfony/process": "^4.4|^5.0|^6.0",
"symfony/uid": "^5.1|^6.0",
"twig/twig": "^2.13|~3.8.0"
"twig/twig": "^2.13|^3.0.4"
},
"conflict": {
"symfony/console": "<4.4"
Expand Down

0 comments on commit e6427c2

Please sign in to comment.