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 4a026c3

Browse filesBrowse files
committed
use reproducible variable names in the default domain node visitor
1 parent 9b0ca99 commit 4a026c3
Copy full SHA for 4a026c3

File tree

1 file changed

+13
-6
lines changed
Filter options

1 file changed

+13
-6
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/NodeVisitor/TranslationDefaultDomainNodeVisitor.php
+13-6Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
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;
2423
use Twig\Node\Expression\Variable\ContextVariable;
24+
use Twig\Node\Expression\Variable\LocalVariable;
2525
use Twig\Node\ModuleNode;
2626
use Twig\Node\Node;
2727
use Twig\Node\Nodes;
@@ -33,8 +33,6 @@
3333
*/
3434
final class TranslationDefaultDomainNodeVisitor implements NodeVisitorInterface
3535
{
36-
private const INTERNAL_VAR_NAME = '__internal_trans_default_domain';
37-
3836
private Scope $scope;
3937

4038
public function __construct()
@@ -55,13 +53,22 @@ public function enterNode(Node $node, Environment $env): Node
5553
return $node;
5654
}
5755

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-
6156
if (class_exists(Nodes::class)) {
57+
$name = new LocalVariable(null, $node->getTemplateLine());
58+
$this->scope->set('domain', $name);
59+
6260
return new SetNode(false, new Nodes([$name]), new Nodes([$node->getNode('expr')]), $node->getTemplateLine());
6361
}
6462

63+
$var = '__internal_trans_default_domain';
64+
65+
if (null !== $templateName = $node->getTemplateName()) {
66+
$var .= hash('xxh128', $templateName);
67+
}
68+
69+
$name = new AssignNameExpression($var, $node->getTemplateLine());
70+
$this->scope->set('domain', new NameExpression($var, $node->getTemplateLine()));
71+
6572
return new SetNode(false, new Node([$name]), new Node([$node->getNode('expr')]), $node->getTemplateLine());
6673
}
6774

0 commit comments

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