Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 79e25a9

Browse files
committed
bug #19983 [TwigBridge] removed Twig null nodes (deprecated as of Twig 1.25) (fabpot)
This PR was merged into the 2.7 branch. Discussion ---------- [TwigBridge] removed Twig null nodes (deprecated as of Twig 1.25) | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes (more about removing deprecation notices from newer versions of Twig) | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a (see twigphp/Twig#2123) | License | MIT | Doc PR | n/a Commits ------- 12350c2 [TwigBridge] removed Twig null nodes (deprecated as of Twig 1.25)
2 parents 2d08be1 + 12350c2 commit 79e25a9

File tree

5 files changed

+33
-21
lines changed

5 files changed

+33
-21
lines changed

src/Symfony/Bridge/Twig/Node/DumpNode.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ class DumpNode extends \Twig_Node
2020

2121
public function __construct($varPrefix, \Twig_Node $values = null, $lineno, $tag = null)
2222
{
23-
parent::__construct(array('values' => $values), array(), $lineno, $tag);
23+
$nodes = array();
24+
if (null !== $values) {
25+
$nodes['values'] = $values;
26+
}
27+
28+
parent::__construct($nodes, array(), $lineno, $tag);
2429
$this->varPrefix = $varPrefix;
2530
}
2631

@@ -33,9 +38,7 @@ public function compile(\Twig_Compiler $compiler)
3338
->write("if (\$this->env->isDebug()) {\n")
3439
->indent();
3540

36-
$values = $this->getNode('values');
37-
38-
if (null === $values) {
41+
if (!$this->hasNode('values')) {
3942
// remove embedded templates (macros) from the context
4043
$compiler
4144
->write(sprintf('$%svars = array();'."\n", $this->varPrefix))
@@ -50,7 +53,7 @@ public function compile(\Twig_Compiler $compiler)
5053
->write("}\n")
5154
->addDebugInfo($this)
5255
->write(sprintf('\Symfony\Component\VarDumper\VarDumper::dump($%svars);'."\n", $this->varPrefix));
53-
} elseif (1 === $values->count()) {
56+
} elseif (($values = $this->getNode('values')) && 1 === $values->count()) {
5457
$compiler
5558
->addDebugInfo($this)
5659
->write('\Symfony\Component\VarDumper\VarDumper::dump(')

src/Symfony/Bridge/Twig/Node/StopwatchNode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
class StopwatchNode extends \Twig_Node
2020
{
21-
public function __construct(\Twig_Node $name, $body, \Twig_Node_Expression_AssignName $var, $lineno = 0, $tag = null)
21+
public function __construct(\Twig_Node $name, \Twig_Node $body, \Twig_Node_Expression_AssignName $var, $lineno = 0, $tag = null)
2222
{
2323
parent::__construct(array('body' => $body, 'name' => $name, 'var' => $var), array(), $lineno, $tag);
2424
}

src/Symfony/Bridge/Twig/Node/TransNode.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,21 @@ class TransNode extends \Twig_Node
1818
{
1919
public function __construct(\Twig_Node $body, \Twig_Node $domain = null, \Twig_Node_Expression $count = null, \Twig_Node_Expression $vars = null, \Twig_Node_Expression $locale = null, $lineno = 0, $tag = null)
2020
{
21-
parent::__construct(array('count' => $count, 'body' => $body, 'domain' => $domain, 'vars' => $vars, 'locale' => $locale), array(), $lineno, $tag);
21+
$nodes = array('body' => $body);
22+
if (null !== $domain) {
23+
$nodes['domain'] = $domain;
24+
}
25+
if (null !== $count) {
26+
$nodes['count'] = $count;
27+
}
28+
if (null !== $vars) {
29+
$nodes['vars'] = $vars;
30+
}
31+
if (null !== $locale) {
32+
$nodes['locale'] = $locale;
33+
}
34+
35+
parent::__construct($nodes, array(), $lineno, $tag);
2236
}
2337

2438
/**
@@ -30,15 +44,14 @@ public function compile(\Twig_Compiler $compiler)
3044
{
3145
$compiler->addDebugInfo($this);
3246

33-
$vars = $this->getNode('vars');
3447
$defaults = new \Twig_Node_Expression_Array(array(), -1);
35-
if ($vars instanceof \Twig_Node_Expression_Array) {
48+
if ($this->hasNode('vars') && ($vars = $this->getNode('vars')) instanceof \Twig_Node_Expression_Array) {
3649
$defaults = $this->getNode('vars');
3750
$vars = null;
3851
}
3952
list($msg, $defaults) = $this->compileString($this->getNode('body'), $defaults, (bool) $vars);
4053

41-
$method = null === $this->getNode('count') ? 'trans' : 'transChoice';
54+
$method = !$this->hasNode('count') ? 'trans' : 'transChoice';
4255

4356
$compiler
4457
->write('echo $this->env->getExtension(\'translator\')->getTranslator()->'.$method.'(')
@@ -47,7 +60,7 @@ public function compile(\Twig_Compiler $compiler)
4760

4861
$compiler->raw(', ');
4962

50-
if (null !== $this->getNode('count')) {
63+
if ($this->hasNode('count')) {
5164
$compiler
5265
->subcompile($this->getNode('count'))
5366
->raw(', ')
@@ -68,13 +81,13 @@ public function compile(\Twig_Compiler $compiler)
6881

6982
$compiler->raw(', ');
7083

71-
if (null === $this->getNode('domain')) {
84+
if (!$this->hasNode('domain')) {
7285
$compiler->repr('messages');
7386
} else {
7487
$compiler->subcompile($this->getNode('domain'));
7588
}
7689

77-
if (null !== $this->getNode('locale')) {
90+
if ($this->hasNode('locale')) {
7891
$compiler
7992
->raw(', ')
8093
->subcompile($this->getNode('locale'))
@@ -98,7 +111,7 @@ protected function compileString(\Twig_Node $body, \Twig_Node_Expression_Array $
98111
foreach ($matches[1] as $var) {
99112
$key = new \Twig_Node_Expression_Constant('%'.$var.'%', $body->getLine());
100113
if (!$vars->hasElement($key)) {
101-
if ('count' === $var && null !== $this->getNode('count')) {
114+
if ('count' === $var && $this->hasNode('count')) {
102115
$vars->addElement($this->getNode('count'), $key);
103116
} else {
104117
$varExpr = new \Twig_Node_Expression_Name($var, $body->getLine());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected function doEnterNode(\Twig_Node $node, \Twig_Environment $env)
7878
}
7979
}
8080
} elseif ($node instanceof TransNode) {
81-
if (null === $node->getNode('domain')) {
81+
if (!$node->hasNode('domain')) {
8282
$node->setNode('domain', $this->scope->get('domain'));
8383
}
8484
}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ protected function doEnterNode(\Twig_Node $node, \Twig_Environment $env)
7575
// extract trans nodes
7676
$this->messages[] = array(
7777
$node->getNode('body')->getAttribute('data'),
78-
$this->getReadDomainFromNode($node->getNode('domain')),
78+
$node->hasNode('domain') ? $this->getReadDomainFromNode($node->getNode('domain')) : null,
7979
);
8080
}
8181

@@ -122,12 +122,8 @@ private function getReadDomainFromArguments(\Twig_Node $arguments, $index)
122122
*
123123
* @return string|null
124124
*/
125-
private function getReadDomainFromNode(\Twig_Node $node = null)
125+
private function getReadDomainFromNode(\Twig_Node $node)
126126
{
127-
if (null === $node) {
128-
return;
129-
}
130-
131127
if ($node instanceof \Twig_Node_Expression_Constant) {
132128
return $node->getAttribute('value');
133129
}

0 commit comments

Comments
 (0)