Simplified Twig_Node_Include

This commit is contained in:
Martin Hasoň
2014-07-30 23:27:46 +02:00
parent 4134169b67
commit 632fe90000
2 changed files with 16 additions and 31 deletions
+15 -29
View File
@@ -60,40 +60,26 @@ class Twig_Node_Include extends Twig_Node implements Twig_NodeOutputInterface
protected function addGetTemplate(Twig_Compiler $compiler)
{
if ($this->getNode('expr') instanceof Twig_Node_Expression_Constant) {
$compiler
->write("\$this->env->loadTemplate(")
->subcompile($this->getNode('expr'))
->raw(")")
;
} else {
$compiler
->write("\$template = \$this->env->resolveTemplate(")
->subcompile($this->getNode('expr'))
->raw(");\n")
->write('$template')
;
}
$method = $this->getNode('expr') instanceof Twig_Node_Expression_Constant ? 'loadTemplate' : 'resolveTemplate';
$compiler
->write(sprintf('$this->env->%s(', $method))
->subcompile($this->getNode('expr'))
->raw(')')
;
}
protected function addTemplateArguments(Twig_Compiler $compiler)
{
if (false === $this->getAttribute('only')) {
if (null === $this->getNode('variables')) {
$compiler->raw('$context');
} else {
$compiler
->raw('array_merge($context, ')
->subcompile($this->getNode('variables'))
->raw(')')
;
}
if (null === $this->getNode('variables')) {
$compiler->raw(false === $this->getAttribute('only') ? '$context' : 'array()');
} elseif (false === $this->getAttribute('only')) {
$compiler
->raw('array_merge($context, ')
->subcompile($this->getNode('variables'))
->raw(')')
;
} else {
if (null === $this->getNode('variables')) {
$compiler->raw('array()');
} else {
$compiler->subcompile($this->getNode('variables'));
}
$compiler->subcompile($this->getNode('variables'));
}
}
}
+1 -2
View File
@@ -59,8 +59,7 @@ EOF
$node = new Twig_Node_Include($expr, null, false, false, 1);
$tests[] = array($node, <<<EOF
// line 1
\$template = \$this->env->resolveTemplate(((true) ? ("foo") : ("foo")));
\$template->display(\$context);
\$this->env->resolveTemplate(((true) ? ("foo") : ("foo")))->display(\$context);
EOF
);