{
public function __construct(Twig_Node_Expression $node, Twig_Node_Expression $attribute, Twig_NodeInterface $arguments, $type, $lineno)
{
- parent::__construct(array('node' => $node, 'attribute' => $attribute, 'arguments' => $arguments), array('type' => $type), $lineno);
+ parent::__construct(array('node' => $node, 'attribute' => $attribute, 'arguments' => $arguments), array('type' => $type, 'is_defined_test' => false), $lineno);
}
public function compile(Twig_Compiler $compiler)
{
$compiler->raw('$this->getAttribute(');
- if ($this->hasAttribute('is_defined_test') && $compiler->getEnvironment()->isStrictVariables()) {
+ if ($this->getAttribute('is_defined_test') && $compiler->getEnvironment()->isStrictVariables()) {
$compiler->subcompile(new Twig_Node_Expression_Filter(
$this->getNode('node'),
new Twig_Node_Expression_Constant('default', $this->getLine()),
$compiler->subcompile($this->getNode('node'));
}
- $compiler
- ->raw(', ')
- ->subcompile($this->getNode('attribute'))
- ->raw(', array(')
- ;
-
- foreach ($this->getNode('arguments') as $node) {
- $compiler
- ->subcompile($node)
- ->raw(', ')
- ;
+ $compiler->raw(', ')->subcompile($this->getNode('attribute'));
+
+ if (count($this->getNode('arguments')) || Twig_TemplateInterface::ANY_CALL !== $this->getAttribute('type') || $this->getAttribute('is_defined_test')) {
+ $compiler->raw(', array(');
+
+ foreach ($this->getNode('arguments') as $node) {
+ $compiler
+ ->subcompile($node)
+ ->raw(', ')
+ ;
+ }
+
+ $compiler->raw(')');
+
+ if (Twig_TemplateInterface::ANY_CALL !== $this->getAttribute('type') || $this->getAttribute('is_defined_test')) {
+ $compiler->raw(', ')->repr($this->getAttribute('type'));
+ }
+
+ if ($this->getAttribute('is_defined_test')) {
+ $compiler->raw(', true');
+ }
}
- $compiler
- ->raw('), ')
- ->repr($this->getAttribute('type'))
- ->raw($this->hasAttribute('is_defined_test') ? ', true' : ', false')
- ->raw(')');
+ $compiler->raw(')');
}
}
public function __construct($name, $lineno)
{
- parent::__construct(array(), array('name' => $name), $lineno);
+ parent::__construct(array(), array('name' => $name, 'is_defined_test' => false), $lineno);
}
public function compile(Twig_Compiler $compiler)
{
$name = $this->getAttribute('name');
- if ($this->hasAttribute('is_defined_test')) {
+ if ($this->getAttribute('is_defined_test')) {
if ($this->isSpecial()) {
$compiler->repr(true);
} else {
public function isSimple()
{
- return !$this->isSpecial() && !$this->hasAttribute('is_defined_test');
+ return !$this->isSpecial() && !$this->getAttribute('is_defined_test');
}
}
$attr = new Twig_Node_Expression_Constant('bar', 0);
$args = new Twig_Node();
$node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_TemplateInterface::ANY_CALL, 0);
- $tests[] = array($node, '$this->getAttribute($this->getContext($context, "foo"), "bar", array(), "any", false)');
+ $tests[] = array($node, '$this->getAttribute($this->getContext($context, "foo"), "bar")');
$node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_TemplateInterface::ARRAY_CALL, 0);
- $tests[] = array($node, '$this->getAttribute($this->getContext($context, "foo"), "bar", array(), "array", false)');
+ $tests[] = array($node, '$this->getAttribute($this->getContext($context, "foo"), "bar", array(), "array")');
$args = new Twig_Node(array(
new Twig_Node_Expression_Constant('bar', 0),
));
$node = new Twig_Node_Expression_GetAttr($expr, $attr, $args, Twig_TemplateInterface::METHOD_CALL, 0);
- $tests[] = array($node, '$this->getAttribute($this->getContext($context, "foo"), "bar", array($this->getContext($context, "foo"), "bar", ), "method", false)');
+ $tests[] = array($node, '$this->getAttribute($this->getContext($context, "foo"), "bar", array($this->getContext($context, "foo"), "bar", ), "method")');
return $tests;
}