summaryrefslogtreecommitdiff
path: root/inc/lib/Twig/Node/Expression/GetAttr.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/lib/Twig/Node/Expression/GetAttr.php')
-rw-r--r--inc/lib/Twig/Node/Expression/GetAttr.php49
1 files changed, 35 insertions, 14 deletions
diff --git a/inc/lib/Twig/Node/Expression/GetAttr.php b/inc/lib/Twig/Node/Expression/GetAttr.php
index 55d9fcc3..b7823acc 100644
--- a/inc/lib/Twig/Node/Expression/GetAttr.php
+++ b/inc/lib/Twig/Node/Expression/GetAttr.php
@@ -3,21 +3,30 @@
/*
* This file is part of Twig.
*
- * (c) 2009 Fabien Potencier
- * (c) 2009 Armin Ronacher
+ * (c) Fabien Potencier
+ * (c) Armin Ronacher
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class Twig_Node_Expression_GetAttr extends Twig_Node_Expression
{
- public function __construct(Twig_Node_Expression $node, Twig_Node_Expression $attribute, Twig_Node_Expression_Array $arguments, $type, $lineno)
+ public function __construct(Twig_Node_Expression $node, Twig_Node_Expression $attribute, Twig_Node_Expression $arguments = null, $type, $lineno)
{
- parent::__construct(array('node' => $node, 'attribute' => $attribute, 'arguments' => $arguments), array('type' => $type, 'is_defined_test' => false, 'ignore_strict_check' => false, 'disable_c_ext' => false), $lineno);
+ $nodes = array('node' => $node, 'attribute' => $attribute);
+ if (null !== $arguments) {
+ $nodes['arguments'] = $arguments;
+ }
+
+ parent::__construct($nodes, array('type' => $type, 'is_defined_test' => false, 'ignore_strict_check' => false, 'disable_c_ext' => false), $lineno);
}
public function compile(Twig_Compiler $compiler)
{
+ if ($this->getAttribute('disable_c_ext')) {
+ @trigger_error(sprintf('Using the "disable_c_ext" attribute on %s is deprecated since version 1.30 and will be removed in 2.0.', __CLASS__), E_USER_DEPRECATED);
+ }
+
if (function_exists('twig_template_get_attributes') && !$this->getAttribute('disable_c_ext')) {
$compiler->raw('twig_template_get_attributes($this, ');
} else {
@@ -32,22 +41,34 @@ class Twig_Node_Expression_GetAttr extends Twig_Node_Expression
$compiler->raw(', ')->subcompile($this->getNode('attribute'));
- if (count($this->getNode('arguments')) || Twig_Template::ANY_CALL !== $this->getAttribute('type') || $this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) {
- $compiler->raw(', ')->subcompile($this->getNode('arguments'));
+ // only generate optional arguments when needed (to make generated code more readable)
+ $needFourth = $this->getAttribute('ignore_strict_check');
+ $needThird = $needFourth || $this->getAttribute('is_defined_test');
+ $needSecond = $needThird || Twig_Template::ANY_CALL !== $this->getAttribute('type');
+ $needFirst = $needSecond || $this->hasNode('arguments');
- if (Twig_Template::ANY_CALL !== $this->getAttribute('type') || $this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) {
- $compiler->raw(', ')->repr($this->getAttribute('type'));
+ if ($needFirst) {
+ if ($this->hasNode('arguments')) {
+ $compiler->raw(', ')->subcompile($this->getNode('arguments'));
+ } else {
+ $compiler->raw(', array()');
}
+ }
- if ($this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) {
- $compiler->raw(', '.($this->getAttribute('is_defined_test') ? 'true' : 'false'));
- }
+ if ($needSecond) {
+ $compiler->raw(', ')->repr($this->getAttribute('type'));
+ }
- if ($this->getAttribute('ignore_strict_check')) {
- $compiler->raw(', '.($this->getAttribute('ignore_strict_check') ? 'true' : 'false'));
- }
+ if ($needThird) {
+ $compiler->raw(', ')->repr($this->getAttribute('is_defined_test'));
+ }
+
+ if ($needFourth) {
+ $compiler->raw(', ')->repr($this->getAttribute('ignore_strict_check'));
}
$compiler->raw(')');
}
}
+
+class_alias('Twig_Node_Expression_GetAttr', 'Twig\Node\Expression\GetAttrExpression', false);