[TwigBridge] removed Twig null nodes (deprecated as of Twig 1.25)
This commit is contained in:
parent
2d08be14f5
commit
12350c2eb1
@ -20,7 +20,12 @@ class DumpNode extends \Twig_Node
|
|||||||
|
|
||||||
public function __construct($varPrefix, \Twig_Node $values = null, $lineno, $tag = null)
|
public function __construct($varPrefix, \Twig_Node $values = null, $lineno, $tag = null)
|
||||||
{
|
{
|
||||||
parent::__construct(array('values' => $values), array(), $lineno, $tag);
|
$nodes = array();
|
||||||
|
if (null !== $values) {
|
||||||
|
$nodes['values'] = $values;
|
||||||
|
}
|
||||||
|
|
||||||
|
parent::__construct($nodes, array(), $lineno, $tag);
|
||||||
$this->varPrefix = $varPrefix;
|
$this->varPrefix = $varPrefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,9 +38,7 @@ class DumpNode extends \Twig_Node
|
|||||||
->write("if (\$this->env->isDebug()) {\n")
|
->write("if (\$this->env->isDebug()) {\n")
|
||||||
->indent();
|
->indent();
|
||||||
|
|
||||||
$values = $this->getNode('values');
|
if (!$this->hasNode('values')) {
|
||||||
|
|
||||||
if (null === $values) {
|
|
||||||
// remove embedded templates (macros) from the context
|
// remove embedded templates (macros) from the context
|
||||||
$compiler
|
$compiler
|
||||||
->write(sprintf('$%svars = array();'."\n", $this->varPrefix))
|
->write(sprintf('$%svars = array();'."\n", $this->varPrefix))
|
||||||
@ -50,7 +53,7 @@ class DumpNode extends \Twig_Node
|
|||||||
->write("}\n")
|
->write("}\n")
|
||||||
->addDebugInfo($this)
|
->addDebugInfo($this)
|
||||||
->write(sprintf('\Symfony\Component\VarDumper\VarDumper::dump($%svars);'."\n", $this->varPrefix));
|
->write(sprintf('\Symfony\Component\VarDumper\VarDumper::dump($%svars);'."\n", $this->varPrefix));
|
||||||
} elseif (1 === $values->count()) {
|
} elseif (($values = $this->getNode('values')) && 1 === $values->count()) {
|
||||||
$compiler
|
$compiler
|
||||||
->addDebugInfo($this)
|
->addDebugInfo($this)
|
||||||
->write('\Symfony\Component\VarDumper\VarDumper::dump(')
|
->write('\Symfony\Component\VarDumper\VarDumper::dump(')
|
||||||
|
@ -18,7 +18,7 @@ namespace Symfony\Bridge\Twig\Node;
|
|||||||
*/
|
*/
|
||||||
class StopwatchNode extends \Twig_Node
|
class StopwatchNode extends \Twig_Node
|
||||||
{
|
{
|
||||||
public function __construct(\Twig_Node $name, $body, \Twig_Node_Expression_AssignName $var, $lineno = 0, $tag = null)
|
public function __construct(\Twig_Node $name, \Twig_Node $body, \Twig_Node_Expression_AssignName $var, $lineno = 0, $tag = null)
|
||||||
{
|
{
|
||||||
parent::__construct(array('body' => $body, 'name' => $name, 'var' => $var), array(), $lineno, $tag);
|
parent::__construct(array('body' => $body, 'name' => $name, 'var' => $var), array(), $lineno, $tag);
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,21 @@ class TransNode extends \Twig_Node
|
|||||||
{
|
{
|
||||||
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)
|
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)
|
||||||
{
|
{
|
||||||
parent::__construct(array('count' => $count, 'body' => $body, 'domain' => $domain, 'vars' => $vars, 'locale' => $locale), array(), $lineno, $tag);
|
$nodes = array('body' => $body);
|
||||||
|
if (null !== $domain) {
|
||||||
|
$nodes['domain'] = $domain;
|
||||||
|
}
|
||||||
|
if (null !== $count) {
|
||||||
|
$nodes['count'] = $count;
|
||||||
|
}
|
||||||
|
if (null !== $vars) {
|
||||||
|
$nodes['vars'] = $vars;
|
||||||
|
}
|
||||||
|
if (null !== $locale) {
|
||||||
|
$nodes['locale'] = $locale;
|
||||||
|
}
|
||||||
|
|
||||||
|
parent::__construct($nodes, array(), $lineno, $tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -30,15 +44,14 @@ class TransNode extends \Twig_Node
|
|||||||
{
|
{
|
||||||
$compiler->addDebugInfo($this);
|
$compiler->addDebugInfo($this);
|
||||||
|
|
||||||
$vars = $this->getNode('vars');
|
|
||||||
$defaults = new \Twig_Node_Expression_Array(array(), -1);
|
$defaults = new \Twig_Node_Expression_Array(array(), -1);
|
||||||
if ($vars instanceof \Twig_Node_Expression_Array) {
|
if ($this->hasNode('vars') && ($vars = $this->getNode('vars')) instanceof \Twig_Node_Expression_Array) {
|
||||||
$defaults = $this->getNode('vars');
|
$defaults = $this->getNode('vars');
|
||||||
$vars = null;
|
$vars = null;
|
||||||
}
|
}
|
||||||
list($msg, $defaults) = $this->compileString($this->getNode('body'), $defaults, (bool) $vars);
|
list($msg, $defaults) = $this->compileString($this->getNode('body'), $defaults, (bool) $vars);
|
||||||
|
|
||||||
$method = null === $this->getNode('count') ? 'trans' : 'transChoice';
|
$method = !$this->hasNode('count') ? 'trans' : 'transChoice';
|
||||||
|
|
||||||
$compiler
|
$compiler
|
||||||
->write('echo $this->env->getExtension(\'translator\')->getTranslator()->'.$method.'(')
|
->write('echo $this->env->getExtension(\'translator\')->getTranslator()->'.$method.'(')
|
||||||
@ -47,7 +60,7 @@ class TransNode extends \Twig_Node
|
|||||||
|
|
||||||
$compiler->raw(', ');
|
$compiler->raw(', ');
|
||||||
|
|
||||||
if (null !== $this->getNode('count')) {
|
if ($this->hasNode('count')) {
|
||||||
$compiler
|
$compiler
|
||||||
->subcompile($this->getNode('count'))
|
->subcompile($this->getNode('count'))
|
||||||
->raw(', ')
|
->raw(', ')
|
||||||
@ -68,13 +81,13 @@ class TransNode extends \Twig_Node
|
|||||||
|
|
||||||
$compiler->raw(', ');
|
$compiler->raw(', ');
|
||||||
|
|
||||||
if (null === $this->getNode('domain')) {
|
if (!$this->hasNode('domain')) {
|
||||||
$compiler->repr('messages');
|
$compiler->repr('messages');
|
||||||
} else {
|
} else {
|
||||||
$compiler->subcompile($this->getNode('domain'));
|
$compiler->subcompile($this->getNode('domain'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null !== $this->getNode('locale')) {
|
if ($this->hasNode('locale')) {
|
||||||
$compiler
|
$compiler
|
||||||
->raw(', ')
|
->raw(', ')
|
||||||
->subcompile($this->getNode('locale'))
|
->subcompile($this->getNode('locale'))
|
||||||
@ -98,7 +111,7 @@ class TransNode extends \Twig_Node
|
|||||||
foreach ($matches[1] as $var) {
|
foreach ($matches[1] as $var) {
|
||||||
$key = new \Twig_Node_Expression_Constant('%'.$var.'%', $body->getLine());
|
$key = new \Twig_Node_Expression_Constant('%'.$var.'%', $body->getLine());
|
||||||
if (!$vars->hasElement($key)) {
|
if (!$vars->hasElement($key)) {
|
||||||
if ('count' === $var && null !== $this->getNode('count')) {
|
if ('count' === $var && $this->hasNode('count')) {
|
||||||
$vars->addElement($this->getNode('count'), $key);
|
$vars->addElement($this->getNode('count'), $key);
|
||||||
} else {
|
} else {
|
||||||
$varExpr = new \Twig_Node_Expression_Name($var, $body->getLine());
|
$varExpr = new \Twig_Node_Expression_Name($var, $body->getLine());
|
||||||
|
@ -78,7 +78,7 @@ class TranslationDefaultDomainNodeVisitor extends \Twig_BaseNodeVisitor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elseif ($node instanceof TransNode) {
|
} elseif ($node instanceof TransNode) {
|
||||||
if (null === $node->getNode('domain')) {
|
if (!$node->hasNode('domain')) {
|
||||||
$node->setNode('domain', $this->scope->get('domain'));
|
$node->setNode('domain', $this->scope->get('domain'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ class TranslationNodeVisitor extends \Twig_BaseNodeVisitor
|
|||||||
// extract trans nodes
|
// extract trans nodes
|
||||||
$this->messages[] = array(
|
$this->messages[] = array(
|
||||||
$node->getNode('body')->getAttribute('data'),
|
$node->getNode('body')->getAttribute('data'),
|
||||||
$this->getReadDomainFromNode($node->getNode('domain')),
|
$node->hasNode('domain') ? $this->getReadDomainFromNode($node->getNode('domain')) : null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,12 +122,8 @@ class TranslationNodeVisitor extends \Twig_BaseNodeVisitor
|
|||||||
*
|
*
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
private function getReadDomainFromNode(\Twig_Node $node = null)
|
private function getReadDomainFromNode(\Twig_Node $node)
|
||||||
{
|
{
|
||||||
if (null === $node) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($node instanceof \Twig_Node_Expression_Constant) {
|
if ($node instanceof \Twig_Node_Expression_Constant) {
|
||||||
return $node->getAttribute('value');
|
return $node->getAttribute('value');
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user