Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 500d72f

Browse filesBrowse files
xabbuhnicolas-grekas
authored andcommitted
use reproducible variable names in the default domain node visitor
1 parent 9b0ca99 commit 500d72f
Copy full SHA for 500d72f

File tree

1 file changed

+13
-7
lines changed
Filter options

1 file changed

+13
-7
lines changed

‎src/Symfony/Bridge/Twig/NodeVisitor/TranslationDefaultDomainNodeVisitor.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/NodeVisitor/TranslationDefaultDomainNodeVisitor.php
+13-7Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
use Twig\Node\Expression\ConstantExpression;
2121
use Twig\Node\Expression\FilterExpression;
2222
use Twig\Node\Expression\NameExpression;
23-
use Twig\Node\Expression\Variable\AssignContextVariable;
24-
use Twig\Node\Expression\Variable\ContextVariable;
23+
use Twig\Node\Expression\Variable\LocalVariable;
2524
use Twig\Node\ModuleNode;
2625
use Twig\Node\Node;
2726
use Twig\Node\Nodes;
@@ -33,9 +32,8 @@
3332
*/
3433
final class TranslationDefaultDomainNodeVisitor implements NodeVisitorInterface
3534
{
36-
private const INTERNAL_VAR_NAME = '__internal_trans_default_domain';
37-
3835
private Scope $scope;
36+
private int $nestingLevel = 0;
3937

4038
public function __construct()
4139
{
@@ -49,19 +47,25 @@ public function enterNode(Node $node, Environment $env): Node
4947
}
5048

5149
if ($node instanceof TransDefaultDomainNode) {
50+
++$this->nestingLevel;
51+
5252
if ($node->getNode('expr') instanceof ConstantExpression) {
5353
$this->scope->set('domain', $node->getNode('expr'));
5454

5555
return $node;
5656
}
5757

58-
$name = class_exists(AssignContextVariable::class) ? new AssignContextVariable(self::INTERNAL_VAR_NAME, $node->getTemplateLine()) : new AssignNameExpression(self::INTERNAL_VAR_NAME, $node->getTemplateLine());
59-
$this->scope->set('domain', class_exists(ContextVariable::class) ? new ContextVariable(self::INTERNAL_VAR_NAME, $node->getTemplateLine()) : new NameExpression(self::INTERNAL_VAR_NAME, $node->getTemplateLine()));
60-
6158
if (class_exists(Nodes::class)) {
59+
$name = new LocalVariable(null, $node->getTemplateLine());
60+
$this->scope->set('domain', $name);
61+
6262
return new SetNode(false, new Nodes([$name]), new Nodes([$node->getNode('expr')]), $node->getTemplateLine());
6363
}
6464

65+
$var = '__internal_trans_default_domain_'.$this->nestingLevel;
66+
$name = new AssignNameExpression($var, $node->getTemplateLine());
67+
$this->scope->set('domain', new NameExpression($var, $node->getTemplateLine()));
68+
6569
return new SetNode(false, new Node([$name]), new Node([$node->getNode('expr')]), $node->getTemplateLine());
6670
}
6771

@@ -94,6 +98,8 @@ public function enterNode(Node $node, Environment $env): Node
9498
public function leaveNode(Node $node, Environment $env): ?Node
9599
{
96100
if ($node instanceof TransDefaultDomainNode) {
101+
--$this->nestingLevel;
102+
97103
return null;
98104
}
99105

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.