8000 Use constant var name to cache trans_default_domain expression result · symfony/symfony@ab116bb · GitHub
[go: up one dir, main page]

Skip to content

Commit ab116bb

Browse files
committed
Use constant var name to cache trans_default_domain expression result
1 parent 6c100c9 commit ab116bb

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
*/
3131
final class TranslationDefaultDomainNodeVisitor implements NodeVisitorInterface
3232
{
33+
private const INTERNAL_VAR_NAME = '__internal_trans_default_domain';
34+
3335
private Scope $scope;
3436

3537
public function __construct()
@@ -49,9 +51,8 @@ public function enterNode(Node $node, Environment $env): Node
4951

5052
return $node;
5153
} else {
52-
$var = $this->getVarName();
53-
$name = new AssignNameExpression($var, $node->getTemplateLine());
54-
$this->scope->set('domain', new NameExpression($var, $node->getTemplateLine()));
54+
$name = new AssignNameExpression(self::INTERNAL_VAR_NAME, $node->getTemplateLine());
55+
$this->scope->set('domain', new NameExpression(self::INTERNAL_VAR_NAME, $node->getTemplateLine()));
5556

5657
return new SetNode(false, new Node([$name]), new Node([$node->getNode('expr')]), $node->getTemplateLine());
5758
}
@@ -111,9 +112,4 @@ private function isNamedArguments(Node $arguments): bool
111112

112113
return false;
113114
}
114-
115-
private function getVarName(): string
116-
{
117-
return \sprintf('__internal_%s', hash('xxh128', uniqid(mt_rand(), true)));
118-
}
119115
}

0 commit comments

Comments
 (0)
0