21
21
use Twig \Node \Expression \ConstantExpression ;
22
22
use Twig \Node \Expression \FilterExpression ;
23
23
use Twig \Node \Expression \NameExpression ;
24
- use Twig \Node \Expression \Variable \LocalVariable ;
24
+ use Twig \Node \Expression \Variable \AssignContextVariable ;
25
+ use Twig \Node \Expression \Variable \ContextVariable ;
25
26
use Twig \Node \ModuleNode ;
26
27
use Twig \Node \Node ;
27
28
use Twig \Node \Nodes ;
33
34
*/
34
35
final class TranslationDefaultDomainNodeVisitor implements NodeVisitorInterface
35
36
{
37
+ private const INTERNAL_VAR_NAME = '__internal_trans_default_domain ' ;
38
+
36
39
private Scope $ scope ;
37
- private int $ nestingLevel = 0 ;
40
+ private int $ nameCounter = 0 ;
38
41
39
42
public function __construct ()
40
43
{
@@ -48,24 +51,21 @@ public function enterNode(Node $node, Environment $env): Node
48
51
}
49
52
50
53
if ($ node instanceof TransDefaultDomainNode) {
51
- ++$ this ->nestingLevel ;
52
-
53
54
if ($ node ->getNode ('expr ' ) instanceof ConstantExpression) {
54
55
$ this ->scope ->set ('domain ' , $ node ->getNode ('expr ' ));
55
56
56
57
return $ node ;
57
58
}
58
59
59
60
if (class_exists (Nodes::class)) {
60
- $ name = new LocalVariable ( null , $ node ->getTemplateLine ());
61
- $ this ->scope ->set ('domain ' , $ name );
61
+ $ name = new AssignContextVariable ( self :: INTERNAL_VAR_NAME .(++ $ this -> nameCounter ) , $ node ->getTemplateLine ());
62
+ $ this ->scope ->set ('domain ' , new ContextVariable ( self :: INTERNAL_VAR_NAME .(++ $ this -> nameCounter ), $ node -> getTemplateLine ()) );
62
63
63
64
return new SetNode (false , new Nodes ([$ name ]), new Nodes ([$ node ->getNode ('expr ' )]), $ node ->getTemplateLine ());
64
65
}
65
66
66
- $ var = '__internal_trans_default_domain_ ' .$ this ->nestingLevel ;
67
- $ name = new AssignNameExpression ($ var , $ node ->getTemplateLine ());
68
- $ this ->scope ->set ('domain ' , new NameExpression ($ var , $ node ->getTemplateLine ()));
67
+ $ name = new AssignNameExpression (self ::INTERNAL_VAR_NAME .(++$ this ->nameCounter ), $ node ->getTemplateLine ());
68
+ $ this ->scope ->set ('domain ' , new NameExpression (self ::INTERNAL_VAR_NAME .(++$ this ->nameCounter ), $ node ->getTemplateLine ()));
69
69
70
70
return new SetNode (false , new Node ([$ name ]), new Node ([$ node ->getNode ('expr ' )]), $ node ->getTemplateLine ());
71
71
}
@@ -105,8 +105,6 @@ public function enterNode(Node $node, Environment $env): Node
105
105
public function leaveNode (Node $ node , Environment $ env ): ?Node
106
106
{
107
107
if ($ node instanceof TransDefaultDomainNode) {
108
- --$ this ->nestingLevel ;
109
-
110
108
return null ;
111
109
}
112
110
0 commit comments