summaryrefslogtreecommitdiff
path: root/inc/lib/Twig/Node/Expression
diff options
context:
space:
mode:
authorBenjamin Southall <applemansigloo@gmail.com>2019-02-26 10:11:12 +1000
committerBenjamin Southall <applemansigloo@gmail.com>2019-02-26 10:11:12 +1000
commitf79395851b044689567e0e6c9504acbcaa742782 (patch)
treeee539aee9ffa90e8accd6f130b30a8ebed7a232e /inc/lib/Twig/Node/Expression
parent28f32baf0125ca5085266e73dc5071e5814d8e3b (diff)
Twig update to latest Twig 1.x legacy as per vichan
Diffstat (limited to 'inc/lib/Twig/Node/Expression')
-rw-r--r--inc/lib/Twig/Node/Expression/Array.php13
-rw-r--r--inc/lib/Twig/Node/Expression/AssignName.php11
-rw-r--r--inc/lib/Twig/Node/Expression/Binary.php11
-rw-r--r--inc/lib/Twig/Node/Expression/Binary/Add.php6
-rw-r--r--inc/lib/Twig/Node/Expression/Binary/And.php6
-rw-r--r--inc/lib/Twig/Node/Expression/Binary/BitwiseAnd.php6
-rw-r--r--inc/lib/Twig/Node/Expression/Binary/BitwiseOr.php6
-rw-r--r--inc/lib/Twig/Node/Expression/Binary/BitwiseXor.php6
-rw-r--r--inc/lib/Twig/Node/Expression/Binary/Concat.php6
-rw-r--r--inc/lib/Twig/Node/Expression/Binary/Div.php6
-rw-r--r--inc/lib/Twig/Node/Expression/Binary/EndsWith.php32
-rw-r--r--inc/lib/Twig/Node/Expression/Binary/Equal.php4
-rw-r--r--inc/lib/Twig/Node/Expression/Binary/FloorDiv.php13
-rw-r--r--inc/lib/Twig/Node/Expression/Binary/Greater.php4
-rw-r--r--inc/lib/Twig/Node/Expression/Binary/GreaterEqual.php4
-rw-r--r--inc/lib/Twig/Node/Expression/Binary/In.php9
-rw-r--r--inc/lib/Twig/Node/Expression/Binary/Less.php4
-rw-r--r--inc/lib/Twig/Node/Expression/Binary/LessEqual.php4
-rw-r--r--inc/lib/Twig/Node/Expression/Binary/Matches.php30
-rw-r--r--inc/lib/Twig/Node/Expression/Binary/Mod.php6
-rw-r--r--inc/lib/Twig/Node/Expression/Binary/Mul.php6
-rw-r--r--inc/lib/Twig/Node/Expression/Binary/NotEqual.php4
-rw-r--r--inc/lib/Twig/Node/Expression/Binary/NotIn.php9
-rw-r--r--inc/lib/Twig/Node/Expression/Binary/Or.php6
-rw-r--r--inc/lib/Twig/Node/Expression/Binary/Power.php13
-rw-r--r--inc/lib/Twig/Node/Expression/Binary/Range.php9
-rw-r--r--inc/lib/Twig/Node/Expression/Binary/StartsWith.php32
-rw-r--r--inc/lib/Twig/Node/Expression/Binary/Sub.php6
-rw-r--r--inc/lib/Twig/Node/Expression/BlockReference.php84
-rw-r--r--inc/lib/Twig/Node/Expression/Call.php209
-rw-r--r--inc/lib/Twig/Node/Expression/Conditional.php6
-rw-r--r--inc/lib/Twig/Node/Expression/Constant.php6
-rw-r--r--inc/lib/Twig/Node/Expression/ExtensionReference.php11
-rw-r--r--inc/lib/Twig/Node/Expression/Filter.php9
-rw-r--r--inc/lib/Twig/Node/Expression/Filter/Default.php12
-rw-r--r--inc/lib/Twig/Node/Expression/Function.php16
-rw-r--r--inc/lib/Twig/Node/Expression/GetAttr.php49
-rw-r--r--inc/lib/Twig/Node/Expression/MethodCall.php4
-rw-r--r--inc/lib/Twig/Node/Expression/Name.php28
-rw-r--r--inc/lib/Twig/Node/Expression/NullCoalesce.php48
-rw-r--r--inc/lib/Twig/Node/Expression/Parent.php17
-rw-r--r--inc/lib/Twig/Node/Expression/TempName.php4
-rw-r--r--inc/lib/Twig/Node/Expression/Test.php14
-rw-r--r--inc/lib/Twig/Node/Expression/Test/Constant.php4
-rw-r--r--inc/lib/Twig/Node/Expression/Test/Defined.php17
-rw-r--r--inc/lib/Twig/Node/Expression/Test/Divisibleby.php6
-rw-r--r--inc/lib/Twig/Node/Expression/Test/Even.php4
-rw-r--r--inc/lib/Twig/Node/Expression/Test/Null.php4
-rw-r--r--inc/lib/Twig/Node/Expression/Test/Odd.php4
-rw-r--r--inc/lib/Twig/Node/Expression/Test/Sameas.php4
-rw-r--r--inc/lib/Twig/Node/Expression/Unary.php13
-rw-r--r--inc/lib/Twig/Node/Expression/Unary/Neg.php6
-rw-r--r--inc/lib/Twig/Node/Expression/Unary/Not.php6
-rw-r--r--inc/lib/Twig/Node/Expression/Unary/Pos.php6
54 files changed, 632 insertions, 231 deletions
diff --git a/inc/lib/Twig/Node/Expression/Array.php b/inc/lib/Twig/Node/Expression/Array.php
index 1da785fe..0e77bb08 100644
--- a/inc/lib/Twig/Node/Expression/Array.php
+++ b/inc/lib/Twig/Node/Expression/Array.php
@@ -3,7 +3,7 @@
/*
* This file is part of Twig.
*
- * (c) 2009 Fabien Potencier
+ * (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -43,7 +43,7 @@ class Twig_Node_Expression_Array extends Twig_Node_Expression
foreach ($this->getKeyValuePairs() as $pair) {
// we compare the string representation of the keys
// to avoid comparing the line numbers which are not relevant here.
- if ((string) $key == (string) $pair['key']) {
+ if ((string) $key === (string) $pair['key']) {
return true;
}
}
@@ -54,17 +54,12 @@ class Twig_Node_Expression_Array extends Twig_Node_Expression
public function addElement(Twig_Node_Expression $value, Twig_Node_Expression $key = null)
{
if (null === $key) {
- $key = new Twig_Node_Expression_Constant(++$this->index, $value->getLine());
+ $key = new Twig_Node_Expression_Constant(++$this->index, $value->getTemplateLine());
}
array_push($this->nodes, $key, $value);
}
- /**
- * Compiles the node to PHP.
- *
- * @param Twig_Compiler A Twig_Compiler instance
- */
public function compile(Twig_Compiler $compiler)
{
$compiler->raw('array(');
@@ -84,3 +79,5 @@ class Twig_Node_Expression_Array extends Twig_Node_Expression
$compiler->raw(')');
}
}
+
+class_alias('Twig_Node_Expression_Array', 'Twig\Node\Expression\ArrayExpression', false);
diff --git a/inc/lib/Twig/Node/Expression/AssignName.php b/inc/lib/Twig/Node/Expression/AssignName.php
index 2ddea78c..2e6b4c7c 100644
--- a/inc/lib/Twig/Node/Expression/AssignName.php
+++ b/inc/lib/Twig/Node/Expression/AssignName.php
@@ -3,8 +3,8 @@
/*
* 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.
@@ -12,11 +12,6 @@
class Twig_Node_Expression_AssignName extends Twig_Node_Expression_Name
{
- /**
- * Compiles the node to PHP.
- *
- * @param Twig_Compiler A Twig_Compiler instance
- */
public function compile(Twig_Compiler $compiler)
{
$compiler
@@ -26,3 +21,5 @@ class Twig_Node_Expression_AssignName extends Twig_Node_Expression_Name
;
}
}
+
+class_alias('Twig_Node_Expression_AssignName', 'Twig\Node\Expression\AssignNameExpression', false);
diff --git a/inc/lib/Twig/Node/Expression/Binary.php b/inc/lib/Twig/Node/Expression/Binary.php
index 9dd5de2c..2b545d98 100644
--- a/inc/lib/Twig/Node/Expression/Binary.php
+++ b/inc/lib/Twig/Node/Expression/Binary.php
@@ -3,8 +3,8 @@
/*
* 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.
@@ -16,11 +16,6 @@ abstract class Twig_Node_Expression_Binary extends Twig_Node_Expression
parent::__construct(array('left' => $left, 'right' => $right), array(), $lineno);
}
- /**
- * Compiles the node to PHP.
- *
- * @param Twig_Compiler A Twig_Compiler instance
- */
public function compile(Twig_Compiler $compiler)
{
$compiler
@@ -38,3 +33,5 @@ abstract class Twig_Node_Expression_Binary extends Twig_Node_Expression
abstract public function operator(Twig_Compiler $compiler);
}
+
+class_alias('Twig_Node_Expression_Binary', 'Twig\Node\Expression\Binary\AbstractBinary', false);
diff --git a/inc/lib/Twig/Node/Expression/Binary/Add.php b/inc/lib/Twig/Node/Expression/Binary/Add.php
index 0ef8e117..5a09d836 100644
--- a/inc/lib/Twig/Node/Expression/Binary/Add.php
+++ b/inc/lib/Twig/Node/Expression/Binary/Add.php
@@ -3,8 +3,8 @@
/*
* 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.
@@ -16,3 +16,5 @@ class Twig_Node_Expression_Binary_Add extends Twig_Node_Expression_Binary
return $compiler->raw('+');
}
}
+
+class_alias('Twig_Node_Expression_Binary_Add', 'Twig\Node\Expression\Binary\AddBinary', false);
diff --git a/inc/lib/Twig/Node/Expression/Binary/And.php b/inc/lib/Twig/Node/Expression/Binary/And.php
index d5752ebb..9ffddce6 100644
--- a/inc/lib/Twig/Node/Expression/Binary/And.php
+++ b/inc/lib/Twig/Node/Expression/Binary/And.php
@@ -3,8 +3,8 @@
/*
* 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.
@@ -16,3 +16,5 @@ class Twig_Node_Expression_Binary_And extends Twig_Node_Expression_Binary
return $compiler->raw('&&');
}
}
+
+class_alias('Twig_Node_Expression_Binary_And', 'Twig\Node\Expression\Binary\AndBinary', false);
diff --git a/inc/lib/Twig/Node/Expression/Binary/BitwiseAnd.php b/inc/lib/Twig/Node/Expression/Binary/BitwiseAnd.php
index 9a46d845..e46e9ebf 100644
--- a/inc/lib/Twig/Node/Expression/Binary/BitwiseAnd.php
+++ b/inc/lib/Twig/Node/Expression/Binary/BitwiseAnd.php
@@ -3,8 +3,8 @@
/*
* 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.
@@ -16,3 +16,5 @@ class Twig_Node_Expression_Binary_BitwiseAnd extends Twig_Node_Expression_Binary
return $compiler->raw('&');
}
}
+
+class_alias('Twig_Node_Expression_Binary_BitwiseAnd', 'Twig\Node\Expression\Binary\BitwiseAndBinary', false);
diff --git a/inc/lib/Twig/Node/Expression/Binary/BitwiseOr.php b/inc/lib/Twig/Node/Expression/Binary/BitwiseOr.php
index 058a20bf..5d7f1b7c 100644
--- a/inc/lib/Twig/Node/Expression/Binary/BitwiseOr.php
+++ b/inc/lib/Twig/Node/Expression/Binary/BitwiseOr.php
@@ -3,8 +3,8 @@
/*
* 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.
@@ -16,3 +16,5 @@ class Twig_Node_Expression_Binary_BitwiseOr extends Twig_Node_Expression_Binary
return $compiler->raw('|');
}
}
+
+class_alias('Twig_Node_Expression_Binary_BitwiseOr', 'Twig\Node\Expression\Binary\BitwiseOrBinary', false);
diff --git a/inc/lib/Twig/Node/Expression/Binary/BitwiseXor.php b/inc/lib/Twig/Node/Expression/Binary/BitwiseXor.php
index f4da73d4..82edf516 100644
--- a/inc/lib/Twig/Node/Expression/Binary/BitwiseXor.php
+++ b/inc/lib/Twig/Node/Expression/Binary/BitwiseXor.php
@@ -3,8 +3,8 @@
/*
* 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.
@@ -16,3 +16,5 @@ class Twig_Node_Expression_Binary_BitwiseXor extends Twig_Node_Expression_Binary
return $compiler->raw('^');
}
}
+
+class_alias('Twig_Node_Expression_Binary_BitwiseXor', 'Twig\Node\Expression\Binary\BitwiseXorBinary', false);
diff --git a/inc/lib/Twig/Node/Expression/Binary/Concat.php b/inc/lib/Twig/Node/Expression/Binary/Concat.php
index f9a64627..91abca60 100644
--- a/inc/lib/Twig/Node/Expression/Binary/Concat.php
+++ b/inc/lib/Twig/Node/Expression/Binary/Concat.php
@@ -3,8 +3,8 @@
/*
* 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.
@@ -16,3 +16,5 @@ class Twig_Node_Expression_Binary_Concat extends Twig_Node_Expression_Binary
return $compiler->raw('.');
}
}
+
+class_alias('Twig_Node_Expression_Binary_Concat', 'Twig\Node\Expression\Binary\ConcatBinary', false);
diff --git a/inc/lib/Twig/Node/Expression/Binary/Div.php b/inc/lib/Twig/Node/Expression/Binary/Div.php
index e0797a61..38ffa30c 100644
--- a/inc/lib/Twig/Node/Expression/Binary/Div.php
+++ b/inc/lib/Twig/Node/Expression/Binary/Div.php
@@ -3,8 +3,8 @@
/*
* 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.
@@ -16,3 +16,5 @@ class Twig_Node_Expression_Binary_Div extends Twig_Node_Expression_Binary
return $compiler->raw('/');
}
}
+
+class_alias('Twig_Node_Expression_Binary_Div', 'Twig\Node\Expression\Binary\DivBinary', false);
diff --git a/inc/lib/Twig/Node/Expression/Binary/EndsWith.php b/inc/lib/Twig/Node/Expression/Binary/EndsWith.php
new file mode 100644
index 00000000..85c52937
--- /dev/null
+++ b/inc/lib/Twig/Node/Expression/Binary/EndsWith.php
@@ -0,0 +1,32 @@
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) Fabien Potencier
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+class Twig_Node_Expression_Binary_EndsWith extends Twig_Node_Expression_Binary
+{
+ public function compile(Twig_Compiler $compiler)
+ {
+ $left = $compiler->getVarName();
+ $right = $compiler->getVarName();
+ $compiler
+ ->raw(sprintf('(is_string($%s = ', $left))
+ ->subcompile($this->getNode('left'))
+ ->raw(sprintf(') && is_string($%s = ', $right))
+ ->subcompile($this->getNode('right'))
+ ->raw(sprintf(') && (\'\' === $%2$s || $%2$s === substr($%1$s, -strlen($%2$s))))', $left, $right))
+ ;
+ }
+
+ public function operator(Twig_Compiler $compiler)
+ {
+ return $compiler->raw('');
+ }
+}
+
+class_alias('Twig_Node_Expression_Binary_EndsWith', 'Twig\Node\Expression\Binary\EndsWithBinary', false);
diff --git a/inc/lib/Twig/Node/Expression/Binary/Equal.php b/inc/lib/Twig/Node/Expression/Binary/Equal.php
index 7b1236d0..a6a6946b 100644
--- a/inc/lib/Twig/Node/Expression/Binary/Equal.php
+++ b/inc/lib/Twig/Node/Expression/Binary/Equal.php
@@ -3,7 +3,7 @@
/*
* This file is part of Twig.
*
- * (c) 2010 Fabien Potencier
+ * (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -15,3 +15,5 @@ class Twig_Node_Expression_Binary_Equal extends Twig_Node_Expression_Binary
return $compiler->raw('==');
}
}
+
+class_alias('Twig_Node_Expression_Binary_Equal', 'Twig\Node\Expression\Binary\EqualBinary', false);
diff --git a/inc/lib/Twig/Node/Expression/Binary/FloorDiv.php b/inc/lib/Twig/Node/Expression/Binary/FloorDiv.php
index 7fbd0556..7393bcb8 100644
--- a/inc/lib/Twig/Node/Expression/Binary/FloorDiv.php
+++ b/inc/lib/Twig/Node/Expression/Binary/FloorDiv.php
@@ -3,23 +3,18 @@
/*
* This file is part of Twig.
*
- * (c) 2009 Fabien Potencier
+ * (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class Twig_Node_Expression_Binary_FloorDiv extends Twig_Node_Expression_Binary
{
- /**
- * Compiles the node to PHP.
- *
- * @param Twig_Compiler A Twig_Compiler instance
- */
public function compile(Twig_Compiler $compiler)
{
- $compiler->raw('intval(floor(');
+ $compiler->raw('(int) floor(');
parent::compile($compiler);
- $compiler->raw('))');
+ $compiler->raw(')');
}
public function operator(Twig_Compiler $compiler)
@@ -27,3 +22,5 @@ class Twig_Node_Expression_Binary_FloorDiv extends Twig_Node_Expression_Binary
return $compiler->raw('/');
}
}
+
+class_alias('Twig_Node_Expression_Binary_FloorDiv', 'Twig\Node\Expression\Binary\FloorDivBinary', false);
diff --git a/inc/lib/Twig/Node/Expression/Binary/Greater.php b/inc/lib/Twig/Node/Expression/Binary/Greater.php
index a110bd92..832f9797 100644
--- a/inc/lib/Twig/Node/Expression/Binary/Greater.php
+++ b/inc/lib/Twig/Node/Expression/Binary/Greater.php
@@ -3,7 +3,7 @@
/*
* This file is part of Twig.
*
- * (c) 2010 Fabien Potencier
+ * (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -15,3 +15,5 @@ class Twig_Node_Expression_Binary_Greater extends Twig_Node_Expression_Binary
return $compiler->raw('>');
}
}
+
+class_alias('Twig_Node_Expression_Binary_Greater', 'Twig\Node\Expression\Binary\GreaterBinary', false);
diff --git a/inc/lib/Twig/Node/Expression/Binary/GreaterEqual.php b/inc/lib/Twig/Node/Expression/Binary/GreaterEqual.php
index 3754fed2..c5f76245 100644
--- a/inc/lib/Twig/Node/Expression/Binary/GreaterEqual.php
+++ b/inc/lib/Twig/Node/Expression/Binary/GreaterEqual.php
@@ -3,7 +3,7 @@
/*
* This file is part of Twig.
*
- * (c) 2010 Fabien Potencier
+ * (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -15,3 +15,5 @@ class Twig_Node_Expression_Binary_GreaterEqual extends Twig_Node_Expression_Bina
return $compiler->raw('>=');
}
}
+
+class_alias('Twig_Node_Expression_Binary_GreaterEqual', 'Twig\Node\Expression\Binary\GreaterEqualBinary', false);
diff --git a/inc/lib/Twig/Node/Expression/Binary/In.php b/inc/lib/Twig/Node/Expression/Binary/In.php
index 788f9377..af112448 100644
--- a/inc/lib/Twig/Node/Expression/Binary/In.php
+++ b/inc/lib/Twig/Node/Expression/Binary/In.php
@@ -3,18 +3,13 @@
/*
* This file is part of Twig.
*
- * (c) 2010 Fabien Potencier
+ * (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class Twig_Node_Expression_Binary_In extends Twig_Node_Expression_Binary
{
- /**
- * Compiles the node to PHP.
- *
- * @param Twig_Compiler A Twig_Compiler instance
- */
public function compile(Twig_Compiler $compiler)
{
$compiler
@@ -31,3 +26,5 @@ class Twig_Node_Expression_Binary_In extends Twig_Node_Expression_Binary
return $compiler->raw('in');
}
}
+
+class_alias('Twig_Node_Expression_Binary_In', 'Twig\Node\Expression\Binary\InBinary', false);
diff --git a/inc/lib/Twig/Node/Expression/Binary/Less.php b/inc/lib/Twig/Node/Expression/Binary/Less.php
index 45fd3004..ab8fc1f9 100644
--- a/inc/lib/Twig/Node/Expression/Binary/Less.php
+++ b/inc/lib/Twig/Node/Expression/Binary/Less.php
@@ -3,7 +3,7 @@
/*
* This file is part of Twig.
*
- * (c) 2010 Fabien Potencier
+ * (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -15,3 +15,5 @@ class Twig_Node_Expression_Binary_Less extends Twig_Node_Expression_Binary
return $compiler->raw('<');
}
}
+
+class_alias('Twig_Node_Expression_Binary_Less', 'Twig\Node\Expression\Binary\LessBinary', false);
diff --git a/inc/lib/Twig/Node/Expression/Binary/LessEqual.php b/inc/lib/Twig/Node/Expression/Binary/LessEqual.php
index e38e257c..71a279e9 100644
--- a/inc/lib/Twig/Node/Expression/Binary/LessEqual.php
+++ b/inc/lib/Twig/Node/Expression/Binary/LessEqual.php
@@ -3,7 +3,7 @@
/*
* This file is part of Twig.
*
- * (c) 2010 Fabien Potencier
+ * (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -15,3 +15,5 @@ class Twig_Node_Expression_Binary_LessEqual extends Twig_Node_Expression_Binary
return $compiler->raw('<=');
}
}
+
+class_alias('Twig_Node_Expression_Binary_LessEqual', 'Twig\Node\Expression\Binary\LessEqualBinary', false);
diff --git a/inc/lib/Twig/Node/Expression/Binary/Matches.php b/inc/lib/Twig/Node/Expression/Binary/Matches.php
new file mode 100644
index 00000000..5cb85584
--- /dev/null
+++ b/inc/lib/Twig/Node/Expression/Binary/Matches.php
@@ -0,0 +1,30 @@
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) Fabien Potencier
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+class Twig_Node_Expression_Binary_Matches extends Twig_Node_Expression_Binary
+{
+ public function compile(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->raw('preg_match(')
+ ->subcompile($this->getNode('right'))
+ ->raw(', ')
+ ->subcompile($this->getNode('left'))
+ ->raw(')')
+ ;
+ }
+
+ public function operator(Twig_Compiler $compiler)
+ {
+ return $compiler->raw('');
+ }
+}
+
+class_alias('Twig_Node_Expression_Binary_Matches', 'Twig\Node\Expression\Binary\MatchesBinary', false);
diff --git a/inc/lib/Twig/Node/Expression/Binary/Mod.php b/inc/lib/Twig/Node/Expression/Binary/Mod.php
index 9924114f..28109633 100644
--- a/inc/lib/Twig/Node/Expression/Binary/Mod.php
+++ b/inc/lib/Twig/Node/Expression/Binary/Mod.php
@@ -3,8 +3,8 @@
/*
* 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.
@@ -16,3 +16,5 @@ class Twig_Node_Expression_Binary_Mod extends Twig_Node_Expression_Binary
return $compiler->raw('%');
}
}
+
+class_alias('Twig_Node_Expression_Binary_Mod', 'Twig\Node\Expression\Binary\ModBinary', false);
diff --git a/inc/lib/Twig/Node/Expression/Binary/Mul.php b/inc/lib/Twig/Node/Expression/Binary/Mul.php
index c91529ca..790c6a22 100644
--- a/inc/lib/Twig/Node/Expression/Binary/Mul.php
+++ b/inc/lib/Twig/Node/Expression/Binary/Mul.php
@@ -3,8 +3,8 @@
/*
* 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.
@@ -16,3 +16,5 @@ class Twig_Node_Expression_Binary_Mul extends Twig_Node_Expression_Binary
return $compiler->raw('*');
}
}
+
+class_alias('Twig_Node_Expression_Binary_Mul', 'Twig\Node\Expression\Binary\MulBinary', false);
diff --git a/inc/lib/Twig/Node/Expression/Binary/NotEqual.php b/inc/lib/Twig/Node/Expression/Binary/NotEqual.php
index 26867ba2..bb45c9ed 100644
--- a/inc/lib/Twig/Node/Expression/Binary/NotEqual.php
+++ b/inc/lib/Twig/Node/Expression/Binary/NotEqual.php
@@ -3,7 +3,7 @@
/*
* This file is part of Twig.
*
- * (c) 2010 Fabien Potencier
+ * (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -15,3 +15,5 @@ class Twig_Node_Expression_Binary_NotEqual extends Twig_Node_Expression_Binary
return $compiler->raw('!=');
}
}
+
+class_alias('Twig_Node_Expression_Binary_NotEqual', 'Twig\Node\Expression\Binary\NotEqualBinary', false);
diff --git a/inc/lib/Twig/Node/Expression/Binary/NotIn.php b/inc/lib/Twig/Node/Expression/Binary/NotIn.php
index f347b7b6..9dedf92f 100644
--- a/inc/lib/Twig/Node/Expression/Binary/NotIn.php
+++ b/inc/lib/Twig/Node/Expression/Binary/NotIn.php
@@ -3,18 +3,13 @@
/*
* This file is part of Twig.
*
- * (c) 2010 Fabien Potencier
+ * (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class Twig_Node_Expression_Binary_NotIn extends Twig_Node_Expression_Binary
{
- /**
- * Compiles the node to PHP.
- *
- * @param Twig_Compiler A Twig_Compiler instance
- */
public function compile(Twig_Compiler $compiler)
{
$compiler
@@ -31,3 +26,5 @@ class Twig_Node_Expression_Binary_NotIn extends Twig_Node_Expression_Binary
return $compiler->raw('not in');
}
}
+
+class_alias('Twig_Node_Expression_Binary_NotIn', 'Twig\Node\Expression\Binary\NotInBinary', false);
diff --git a/inc/lib/Twig/Node/Expression/Binary/Or.php b/inc/lib/Twig/Node/Expression/Binary/Or.php
index adba49c6..dc9eece1 100644
--- a/inc/lib/Twig/Node/Expression/Binary/Or.php
+++ b/inc/lib/Twig/Node/Expression/Binary/Or.php
@@ -3,8 +3,8 @@
/*
* 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.
@@ -16,3 +16,5 @@ class Twig_Node_Expression_Binary_Or extends Twig_Node_Expression_Binary
return $compiler->raw('||');
}
}
+
+class_alias('Twig_Node_Expression_Binary_Or', 'Twig\Node\Expression\Binary\OrBinary', false);
diff --git a/inc/lib/Twig/Node/Expression/Binary/Power.php b/inc/lib/Twig/Node/Expression/Binary/Power.php
index b2c59040..d24777bd 100644
--- a/inc/lib/Twig/Node/Expression/Binary/Power.php
+++ b/inc/lib/Twig/Node/Expression/Binary/Power.php
@@ -3,20 +3,19 @@
/*
* This file is part of Twig.
*
- * (c) 2010 Fabien Potencier
+ * (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class Twig_Node_Expression_Binary_Power extends Twig_Node_Expression_Binary
{
- /**
- * Compiles the node to PHP.
- *
- * @param Twig_Compiler A Twig_Compiler instance
- */
public function compile(Twig_Compiler $compiler)
{
+ if (PHP_VERSION_ID >= 50600) {
+ return parent::compile($compiler);
+ }
+
$compiler
->raw('pow(')
->subcompile($this->getNode('left'))
@@ -31,3 +30,5 @@ class Twig_Node_Expression_Binary_Power extends Twig_Node_Expression_Binary
return $compiler->raw('**');
}
}
+
+class_alias('Twig_Node_Expression_Binary_Power', 'Twig\Node\Expression\Binary\PowerBinary', false);
diff --git a/inc/lib/Twig/Node/Expression/Binary/Range.php b/inc/lib/Twig/Node/Expression/Binary/Range.php
index bea4f2a6..187f6765 100644
--- a/inc/lib/Twig/Node/Expression/Binary/Range.php
+++ b/inc/lib/Twig/Node/Expression/Binary/Range.php
@@ -3,18 +3,13 @@
/*
* This file is part of Twig.
*
- * (c) 2010 Fabien Potencier
+ * (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class Twig_Node_Expression_Binary_Range extends Twig_Node_Expression_Binary
{
- /**
- * Compiles the node to PHP.
- *
- * @param Twig_Compiler A Twig_Compiler instance
- */
public function compile(Twig_Compiler $compiler)
{
$compiler
@@ -31,3 +26,5 @@ class Twig_Node_Expression_Binary_Range extends Twig_Node_Expression_Binary
return $compiler->raw('..');
}
}
+
+class_alias('Twig_Node_Expression_Binary_Range', 'Twig\Node\Expression\Binary\RangeBinary', false);
diff --git a/inc/lib/Twig/Node/Expression/Binary/StartsWith.php b/inc/lib/Twig/Node/Expression/Binary/StartsWith.php
new file mode 100644
index 00000000..7e43b8de
--- /dev/null
+++ b/inc/lib/Twig/Node/Expression/Binary/StartsWith.php
@@ -0,0 +1,32 @@
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) Fabien Potencier
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+class Twig_Node_Expression_Binary_StartsWith extends Twig_Node_Expression_Binary
+{
+ public function compile(Twig_Compiler $compiler)
+ {
+ $left = $compiler->getVarName();
+ $right = $compiler->getVarName();
+ $compiler
+ ->raw(sprintf('(is_string($%s = ', $left))
+ ->subcompile($this->getNode('left'))
+ ->raw(sprintf(') && is_string($%s = ', $right))
+ ->subcompile($this->getNode('right'))
+ ->raw(sprintf(') && (\'\' === $%2$s || 0 === strpos($%1$s, $%2$s)))', $left, $right))
+ ;
+ }
+
+ public function operator(Twig_Compiler $compiler)
+ {
+ return $compiler->raw('');
+ }
+}
+
+class_alias('Twig_Node_Expression_Binary_StartsWith', 'Twig\Node\Expression\Binary\StartsWithBinary', false);
diff --git a/inc/lib/Twig/Node/Expression/Binary/Sub.php b/inc/lib/Twig/Node/Expression/Binary/Sub.php
index d4463991..cff8ed07 100644
--- a/inc/lib/Twig/Node/Expression/Binary/Sub.php
+++ b/inc/lib/Twig/Node/Expression/Binary/Sub.php
@@ -3,8 +3,8 @@
/*
* 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.
@@ -16,3 +16,5 @@ class Twig_Node_Expression_Binary_Sub extends Twig_Node_Expression_Binary
return $compiler->raw('-');
}
}
+
+class_alias('Twig_Node_Expression_Binary_Sub', 'Twig\Node\Expression\Binary\SubBinary', false);
diff --git a/inc/lib/Twig/Node/Expression/BlockReference.php b/inc/lib/Twig/Node/Expression/BlockReference.php
index 647196eb..37a3983d 100644
--- a/inc/lib/Twig/Node/Expression/BlockReference.php
+++ b/inc/lib/Twig/Node/Expression/BlockReference.php
@@ -3,8 +3,8 @@
/*
* 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.
@@ -17,35 +17,77 @@
*/
class Twig_Node_Expression_BlockReference extends Twig_Node_Expression
{
- public function __construct(Twig_NodeInterface $name, $asString = false, $lineno, $tag = null)
+ /**
+ * @param Twig_Node|null $template
+ */
+ public function __construct(Twig_NodeInterface $name, $template = null, $lineno, $tag = null)
{
- parent::__construct(array('name' => $name), array('as_string' => $asString, 'output' => false), $lineno, $tag);
+ if (is_bool($template)) {
+ @trigger_error(sprintf('The %s method "$asString" argument is deprecated since version 1.28 and will be removed in 2.0.', __METHOD__), E_USER_DEPRECATED);
+
+ $template = null;
+ }
+
+ $nodes = array('name' => $name);
+ if (null !== $template) {
+ $nodes['template'] = $template;
+ }
+
+ parent::__construct($nodes, array('is_defined_test' => false, 'output' => false), $lineno, $tag);
}
- /**
- * Compiles the node to PHP.
- *
- * @param Twig_Compiler A Twig_Compiler instance
- */
public function compile(Twig_Compiler $compiler)
{
- if ($this->getAttribute('as_string')) {
- $compiler->raw('(string) ');
+ if ($this->getAttribute('is_defined_test')) {
+ $this->compileTemplateCall($compiler, 'hasBlock');
+ } else {
+ if ($this->getAttribute('output')) {
+ $compiler->addDebugInfo($this);
+
+ $this
+ ->compileTemplateCall($compiler, 'displayBlock')
+ ->raw(";\n");
+ } else {
+ $this->compileTemplateCall($compiler, 'renderBlock');
+ }
}
+ }
- if ($this->getAttribute('output')) {
- $compiler
- ->addDebugInfo($this)
- ->write("\$this->displayBlock(")
- ->subcompile($this->getNode('name'))
- ->raw(", \$context, \$blocks);\n")
- ;
+ private function compileTemplateCall(Twig_Compiler $compiler, $method)
+ {
+ if (!$this->hasNode('template')) {
+ $compiler->write('$this');
} else {
$compiler
- ->raw("\$this->renderBlock(")
- ->subcompile($this->getNode('name'))
- ->raw(", \$context, \$blocks)")
+ ->write('$this->loadTemplate(')
+ ->subcompile($this->getNode('template'))
+ ->raw(', ')
+ ->repr($this->getTemplateName())
+ ->raw(', ')
+ ->repr($this->getTemplateLine())
+ ->raw(')')
;
}
+
+ $compiler->raw(sprintf('->%s', $method));
+ $this->compileBlockArguments($compiler);
+
+ return $compiler;
+ }
+
+ private function compileBlockArguments(Twig_Compiler $compiler)
+ {
+ $compiler
+ ->raw('(')
+ ->subcompile($this->getNode('name'))
+ ->raw(', $context');
+
+ if (!$this->hasNode('template')) {
+ $compiler->raw(', $blocks');
+ }
+
+ return $compiler->raw(')');
}
}
+
+class_alias('Twig_Node_Expression_BlockReference', 'Twig\Node\Expression\BlockReferenceExpression', false);
diff --git a/inc/lib/Twig/Node/Expression/Call.php b/inc/lib/Twig/Node/Expression/Call.php
index dba9b0e6..d962b6a5 100644
--- a/inc/lib/Twig/Node/Expression/Call.php
+++ b/inc/lib/Twig/Node/Expression/Call.php
@@ -3,27 +3,36 @@
/*
* This file is part of Twig.
*
- * (c) 2012 Fabien Potencier
+ * (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
abstract class Twig_Node_Expression_Call extends Twig_Node_Expression
{
+ private $reflector;
+
protected function compileCallable(Twig_Compiler $compiler)
{
- $callable = $this->getAttribute('callable');
-
$closingParenthesis = false;
- if ($callable) {
- if (is_string($callable)) {
+ if ($this->hasAttribute('callable') && $callable = $this->getAttribute('callable')) {
+ if (is_string($callable) && false === strpos($callable, '::')) {
$compiler->raw($callable);
- } elseif (is_array($callable) && $callable[0] instanceof Twig_ExtensionInterface) {
- $compiler->raw(sprintf('$this->env->getExtension(\'%s\')->%s', $callable[0]->getName(), $callable[1]));
} else {
- $type = ucfirst($this->getAttribute('type'));
- $compiler->raw(sprintf('call_user_func_array($this->env->get%s(\'%s\')->getCallable(), array', $type, $this->getAttribute('name')));
- $closingParenthesis = true;
+ list($r, $callable) = $this->reflectCallable($callable);
+ if ($r instanceof ReflectionMethod && is_string($callable[0])) {
+ if ($r->isStatic()) {
+ $compiler->raw(sprintf('%s::%s', $callable[0], $callable[1]));
+ } else {
+ $compiler->raw(sprintf('$this->env->getRuntime(\'%s\')->%s', $callable[0], $callable[1]));
+ }
+ } elseif ($r instanceof ReflectionMethod && $callable[0] instanceof Twig_ExtensionInterface) {
+ $compiler->raw(sprintf('$this->env->getExtension(\'%s\')->%s', get_class($callable[0]), $callable[1]));
+ } else {
+ $type = ucfirst($this->getAttribute('type'));
+ $compiler->raw(sprintf('call_user_func_array($this->env->get%s(\'%s\')->getCallable(), array', $type, $this->getAttribute('name')));
+ $closingParenthesis = true;
+ }
}
} else {
$compiler->raw($this->getAttribute('thing')->compile());
@@ -73,7 +82,7 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression
$first = false;
}
- if ($this->hasNode('arguments') && null !== $this->getNode('arguments')) {
+ if ($this->hasNode('arguments')) {
$callable = $this->hasAttribute('callable') ? $this->getAttribute('callable') : null;
$arguments = $this->getArguments($callable, $this->getNode('arguments'));
@@ -92,6 +101,9 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression
protected function getArguments($callable, $arguments)
{
+ $callType = $this->getAttribute('type');
+ $callName = $this->getAttribute('name');
+
$parameters = array();
$named = false;
foreach ($arguments as $name => $node) {
@@ -99,73 +111,101 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression
$named = true;
$name = $this->normalizeName($name);
} elseif ($named) {
- throw new Twig_Error_Syntax(sprintf('Positional arguments cannot be used after named arguments for %s "%s".', $this->getAttribute('type'), $this->getAttribute('name')));
+ throw new Twig_Error_Syntax(sprintf('Positional arguments cannot be used after named arguments for %s "%s".', $callType, $callName));
}
$parameters[$name] = $node;
}
- if (!$named) {
+ $isVariadic = $this->hasAttribute('is_variadic') && $this->getAttribute('is_variadic');
+ if (!$named && !$isVariadic) {
return $parameters;
}
if (!$callable) {
- throw new LogicException(sprintf('Named arguments are not supported for %s "%s".', $this->getAttribute('type'), $this->getAttribute('name')));
- }
-
- // manage named arguments
- if (is_array($callable)) {
- $r = new ReflectionMethod($callable[0], $callable[1]);
- } elseif (is_object($callable) && !$callable instanceof Closure) {
- $r = new ReflectionObject($callable);
- $r = $r->getMethod('__invoke');
- } else {
- $r = new ReflectionFunction($callable);
- }
-
- $definition = $r->getParameters();
- if ($this->hasNode('node')) {
- array_shift($definition);
- }
- if ($this->hasAttribute('needs_environment') && $this->getAttribute('needs_environment')) {
- array_shift($definition);
- }
- if ($this->hasAttribute('needs_context') && $this->getAttribute('needs_context')) {
- array_shift($definition);
- }
- if ($this->hasAttribute('arguments') && null !== $this->getAttribute('arguments')) {
- foreach ($this->getAttribute('arguments') as $argument) {
- array_shift($definition);
+ if ($named) {
+ $message = sprintf('Named arguments are not supported for %s "%s".', $callType, $callName);
+ } else {
+ $message = sprintf('Arbitrary positional arguments are not supported for %s "%s".', $callType, $callName);
}
+
+ throw new LogicException($message);
}
+ $callableParameters = $this->getCallableParameters($callable, $isVariadic);
$arguments = array();
+ $names = array();
+ $missingArguments = array();
+ $optionalArguments = array();
$pos = 0;
- foreach ($definition as $param) {
- $name = $this->normalizeName($param->name);
+ foreach ($callableParameters as $callableParameter) {
+ $names[] = $name = $this->normalizeName($callableParameter->name);
if (array_key_exists($name, $parameters)) {
if (array_key_exists($pos, $parameters)) {
- throw new Twig_Error_Syntax(sprintf('Argument "%s" is defined twice for %s "%s".', $name, $this->getAttribute('type'), $this->getAttribute('name')));
+ throw new Twig_Error_Syntax(sprintf('Argument "%s" is defined twice for %s "%s".', $name, $callType, $callName));
+ }
+
+ if (count($missingArguments)) {
+ throw new Twig_Error_Syntax(sprintf(
+ 'Argument "%s" could not be assigned for %s "%s(%s)" because it is mapped to an internal PHP function which cannot determine default value for optional argument%s "%s".',
+ $name, $callType, $callName, implode(', ', $names), count($missingArguments) > 1 ? 's' : '', implode('", "', $missingArguments))
+ );
}
+ $arguments = array_merge($arguments, $optionalArguments);
$arguments[] = $parameters[$name];
unset($parameters[$name]);
+ $optionalArguments = array();
} elseif (array_key_exists($pos, $parameters)) {
+ $arguments = array_merge($arguments, $optionalArguments);
$arguments[] = $parameters[$pos];
unset($parameters[$pos]);
+ $optionalArguments = array();
++$pos;
- } elseif ($param->isDefaultValueAvailable()) {
- $arguments[] = new Twig_Node_Expression_Constant($param->getDefaultValue(), -1);
- } elseif ($param->isOptional()) {
- break;
+ } elseif ($callableParameter->isDefaultValueAvailable()) {
+ $optionalArguments[] = new Twig_Node_Expression_Constant($callableParameter->getDefaultValue(), -1);
+ } elseif ($callableParameter->isOptional()) {
+ if (empty($parameters)) {
+ break;
+ } else {
+ $missingArguments[] = $name;
+ }
} else {
- throw new Twig_Error_Syntax(sprintf('Value for argument "%s" is required for %s "%s".', $name, $this->getAttribute('type'), $this->getAttribute('name')));
+ throw new Twig_Error_Syntax(sprintf('Value for argument "%s" is required for %s "%s".', $name, $callType, $callName));
+ }
+ }
+
+ if ($isVariadic) {
+ $arbitraryArguments = new Twig_Node_Expression_Array(array(), -1);
+ foreach ($parameters as $key => $value) {
+ if (is_int($key)) {
+ $arbitraryArguments->addElement($value);
+ } else {
+ $arbitraryArguments->addElement($value, new Twig_Node_Expression_Constant($key, -1));
+ }
+ unset($parameters[$key]);
+ }
+
+ if ($arbitraryArguments->count()) {
+ $arguments = array_merge($arguments, $optionalArguments);
+ $arguments[] = $arbitraryArguments;
}
}
if (!empty($parameters)) {
- throw new Twig_Error_Syntax(sprintf('Unknown argument%s "%s" for %s "%s".', count($parameters) > 1 ? 's' : '' , implode('", "', array_keys($parameters)), $this->getAttribute('type'), $this->getAttribute('name')));
+ $unknownParameter = null;
+ foreach ($parameters as $parameter) {
+ if ($parameter instanceof Twig_Node) {
+ $unknownParameter = $parameter;
+ break;
+ }
+ }
+
+ throw new Twig_Error_Syntax(sprintf(
+ 'Unknown argument%s "%s" for %s "%s(%s)".',
+ count($parameters) > 1 ? 's' : '', implode('", "', array_keys($parameters)), $callType, $callName, implode(', ', $names)
+ ), $unknownParameter ? $unknownParameter->getTemplateLine() : -1);
}
return $arguments;
@@ -175,4 +215,77 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression
{
return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), array('\\1_\\2', '\\1_\\2'), $name));
}
+
+ private function getCallableParameters($callable, $isVariadic)
+ {
+ list($r) = $this->reflectCallable($callable);
+ if (null === $r) {
+ return array();
+ }
+
+ $parameters = $r->getParameters();
+ if ($this->hasNode('node')) {
+ array_shift($parameters);
+ }
+ if ($this->hasAttribute('needs_environment') && $this->getAttribute('needs_environment')) {
+ array_shift($parameters);
+ }
+ if ($this->hasAttribute('needs_context') && $this->getAttribute('needs_context')) {
+ array_shift($parameters);
+ }
+ if ($this->hasAttribute('arguments') && null !== $this->getAttribute('arguments')) {
+ foreach ($this->getAttribute('arguments') as $argument) {
+ array_shift($parameters);
+ }
+ }
+ if ($isVariadic) {
+ $argument = end($parameters);
+ if ($argument && $argument->isArray() && $argument->isDefaultValueAvailable() && array() === $argument->getDefaultValue()) {
+ array_pop($parameters);
+ } else {
+ $callableName = $r->name;
+ if ($r instanceof ReflectionMethod) {
+ $callableName = $r->getDeclaringClass()->name.'::'.$callableName;
+ }
+
+ throw new LogicException(sprintf('The last parameter of "%s" for %s "%s" must be an array with default value, eg. "array $arg = array()".', $callableName, $this->getAttribute('type'), $this->getAttribute('name')));
+ }
+ }
+
+ return $parameters;
+ }
+
+ private function reflectCallable($callable)
+ {
+ if (null !== $this->reflector) {
+ return $this->reflector;
+ }
+
+ if (is_array($callable)) {
+ if (!method_exists($callable[0], $callable[1])) {
+ // __call()
+ return array(null, array());
+ }
+ $r = new ReflectionMethod($callable[0], $callable[1]);
+ } elseif (is_object($callable) && !$callable instanceof Closure) {
+ $r = new ReflectionObject($callable);
+ $r = $r->getMethod('__invoke');
+ $callable = array($callable, '__invoke');
+ } elseif (is_string($callable) && false !== $pos = strpos($callable, '::')) {
+ $class = substr($callable, 0, $pos);
+ $method = substr($callable, $pos + 2);
+ if (!method_exists($class, $method)) {
+ // __staticCall()
+ return array(null, array());
+ }
+ $r = new ReflectionMethod($callable);
+ $callable = array($class, $method);
+ } else {
+ $r = new ReflectionFunction($callable);
+ }
+
+ return $this->reflector = array($r, $callable);
+ }
}
+
+class_alias('Twig_Node_Expression_Call', 'Twig\Node\Expression\CallExpression', false);
diff --git a/inc/lib/Twig/Node/Expression/Conditional.php b/inc/lib/Twig/Node/Expression/Conditional.php
index edcb1e2d..c339d773 100644
--- a/inc/lib/Twig/Node/Expression/Conditional.php
+++ b/inc/lib/Twig/Node/Expression/Conditional.php
@@ -3,8 +3,8 @@
/*
* 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.
@@ -29,3 +29,5 @@ class Twig_Node_Expression_Conditional extends Twig_Node_Expression
;
}
}
+
+class_alias('Twig_Node_Expression_Conditional', 'Twig\Node\Expression\ConditionalExpression', false);
diff --git a/inc/lib/Twig/Node/Expression/Constant.php b/inc/lib/Twig/Node/Expression/Constant.php
index a91dc698..bf4d031c 100644
--- a/inc/lib/Twig/Node/Expression/Constant.php
+++ b/inc/lib/Twig/Node/Expression/Constant.php
@@ -3,8 +3,8 @@
/*
* 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.
@@ -21,3 +21,5 @@ class Twig_Node_Expression_Constant extends Twig_Node_Expression
$compiler->repr($this->getAttribute('value'));
}
}
+
+class_alias('Twig_Node_Expression_Constant', 'Twig\Node\Expression\ConstantExpression', false);
diff --git a/inc/lib/Twig/Node/Expression/ExtensionReference.php b/inc/lib/Twig/Node/Expression/ExtensionReference.php
index 00ac6701..114b5cd9 100644
--- a/inc/lib/Twig/Node/Expression/ExtensionReference.php
+++ b/inc/lib/Twig/Node/Expression/ExtensionReference.php
@@ -3,16 +3,20 @@
/*
* This file is part of Twig.
*
- * (c) 2009 Fabien Potencier
+ * (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
+@trigger_error('The Twig_Node_Expression_ExtensionReference class is deprecated since version 1.23 and will be removed in 2.0.', E_USER_DEPRECATED);
+
/**
* Represents an extension call node.
*
* @author Fabien Potencier <fabien@symfony.com>
+ *
+ * @deprecated since 1.23 and will be removed in 2.0.
*/
class Twig_Node_Expression_ExtensionReference extends Twig_Node_Expression
{
@@ -21,11 +25,6 @@ class Twig_Node_Expression_ExtensionReference extends Twig_Node_Expression
parent::__construct(array(), array('name' => $name), $lineno, $tag);
}
- /**
- * Compiles the node to PHP.
- *
- * @param Twig_Compiler A Twig_Compiler instance
- */
public function compile(Twig_Compiler $compiler)
{
$compiler->raw(sprintf("\$this->env->getExtension('%s')", $this->getAttribute('name')));
diff --git a/inc/lib/Twig/Node/Expression/Filter.php b/inc/lib/Twig/Node/Expression/Filter.php
index 207b062a..12da1d67 100644
--- a/inc/lib/Twig/Node/Expression/Filter.php
+++ b/inc/lib/Twig/Node/Expression/Filter.php
@@ -3,8 +3,8 @@
/*
* 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.
@@ -30,7 +30,12 @@ class Twig_Node_Expression_Filter extends Twig_Node_Expression_Call
if ($filter instanceof Twig_FilterCallableInterface || $filter instanceof Twig_SimpleFilter) {
$this->setAttribute('callable', $filter->getCallable());
}
+ if ($filter instanceof Twig_SimpleFilter) {
+ $this->setAttribute('is_variadic', $filter->isVariadic());
+ }
$this->compileCallable($compiler);
}
}
+
+class_alias('Twig_Node_Expression_Filter', 'Twig\Node\Expression\FilterExpression', false);
diff --git a/inc/lib/Twig/Node/Expression/Filter/Default.php b/inc/lib/Twig/Node/Expression/Filter/Default.php
index 1827c888..d2e19d54 100644
--- a/inc/lib/Twig/Node/Expression/Filter/Default.php
+++ b/inc/lib/Twig/Node/Expression/Filter/Default.php
@@ -3,7 +3,7 @@
/*
* This file is part of Twig.
*
- * (c) 2011 Fabien Potencier
+ * (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -22,13 +22,13 @@ class Twig_Node_Expression_Filter_Default extends Twig_Node_Expression_Filter
{
public function __construct(Twig_NodeInterface $node, Twig_Node_Expression_Constant $filterName, Twig_NodeInterface $arguments, $lineno, $tag = null)
{
- $default = new Twig_Node_Expression_Filter($node, new Twig_Node_Expression_Constant('default', $node->getLine()), $arguments, $node->getLine());
+ $default = new Twig_Node_Expression_Filter($node, new Twig_Node_Expression_Constant('default', $node->getTemplateLine()), $arguments, $node->getTemplateLine());
if ('default' === $filterName->getAttribute('value') && ($node instanceof Twig_Node_Expression_Name || $node instanceof Twig_Node_Expression_GetAttr)) {
- $test = new Twig_Node_Expression_Test_Defined(clone $node, 'defined', new Twig_Node(), $node->getLine());
- $false = count($arguments) ? $arguments->getNode(0) : new Twig_Node_Expression_Constant('', $node->getLine());
+ $test = new Twig_Node_Expression_Test_Defined(clone $node, 'defined', new Twig_Node(), $node->getTemplateLine());
+ $false = count($arguments) ? $arguments->getNode(0) : new Twig_Node_Expression_Constant('', $node->getTemplateLine());
- $node = new Twig_Node_Expression_Conditional($test, $default, $false, $node->getLine());
+ $node = new Twig_Node_Expression_Conditional($test, $default, $false, $node->getTemplateLine());
} else {
$node = $default;
}
@@ -41,3 +41,5 @@ class Twig_Node_Expression_Filter_Default extends Twig_Node_Expression_Filter
$compiler->subcompile($this->getNode('node'));
}
}
+
+class_alias('Twig_Node_Expression_Filter_Default', 'Twig\Node\Expression\Filter\DefaultFilter', false);
diff --git a/inc/lib/Twig/Node/Expression/Function.php b/inc/lib/Twig/Node/Expression/Function.php
index 3e1f6b55..cdee7c97 100644
--- a/inc/lib/Twig/Node/Expression/Function.php
+++ b/inc/lib/Twig/Node/Expression/Function.php
@@ -3,7 +3,7 @@
/*
* This file is part of Twig.
*
- * (c) 2010 Fabien Potencier
+ * (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -12,7 +12,7 @@ class Twig_Node_Expression_Function extends Twig_Node_Expression_Call
{
public function __construct($name, Twig_NodeInterface $arguments, $lineno)
{
- parent::__construct(array('arguments' => $arguments), array('name' => $name), $lineno);
+ parent::__construct(array('arguments' => $arguments), array('name' => $name, 'is_defined_test' => false), $lineno);
}
public function compile(Twig_Compiler $compiler)
@@ -27,9 +27,19 @@ class Twig_Node_Expression_Function extends Twig_Node_Expression_Call
$this->setAttribute('needs_context', $function->needsContext());
$this->setAttribute('arguments', $function->getArguments());
if ($function instanceof Twig_FunctionCallableInterface || $function instanceof Twig_SimpleFunction) {
- $this->setAttribute('callable', $function->getCallable());
+ $callable = $function->getCallable();
+ if ('constant' === $name && $this->getAttribute('is_defined_test')) {
+ $callable = 'twig_constant_is_defined';
+ }
+
+ $this->setAttribute('callable', $callable);
+ }
+ if ($function instanceof Twig_SimpleFunction) {
+ $this->setAttribute('is_variadic', $function->isVariadic());
}
$this->compileCallable($compiler);
}
}
+
+class_alias('Twig_Node_Expression_Function', 'Twig\Node\Expression\FunctionExpression', false);
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);
diff --git a/inc/lib/Twig/Node/Expression/MethodCall.php b/inc/lib/Twig/Node/Expression/MethodCall.php
index 620b02bf..709016eb 100644
--- a/inc/lib/Twig/Node/Expression/MethodCall.php
+++ b/inc/lib/Twig/Node/Expression/MethodCall.php
@@ -3,7 +3,7 @@
/*
* This file is part of Twig.
*
- * (c) 2012 Fabien Potencier
+ * (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -39,3 +39,5 @@ class Twig_Node_Expression_MethodCall extends Twig_Node_Expression
$compiler->raw(')');
}
}
+
+class_alias('Twig_Node_Expression_MethodCall', 'Twig\Node\Expression\MethodCallExpression', false);
diff --git a/inc/lib/Twig/Node/Expression/Name.php b/inc/lib/Twig/Node/Expression/Name.php
index 3b8fae01..9d5a21f8 100644
--- a/inc/lib/Twig/Node/Expression/Name.php
+++ b/inc/lib/Twig/Node/Expression/Name.php
@@ -3,8 +3,8 @@
/*
* 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.
@@ -12,7 +12,7 @@
class Twig_Node_Expression_Name extends Twig_Node_Expression
{
protected $specialVars = array(
- '_self' => '$this',
+ '_self' => '$this',
'_context' => '$context',
'_charset' => '$this->env->getCharset()',
);
@@ -26,6 +26,8 @@ class Twig_Node_Expression_Name extends Twig_Node_Expression
{
$name = $this->getAttribute('name');
+ $compiler->addDebugInfo($this);
+
if ($this->getAttribute('is_defined_test')) {
if ($this->isSpecial()) {
$compiler->repr(true);
@@ -41,10 +43,20 @@ class Twig_Node_Expression_Name extends Twig_Node_Expression
->raw(']')
;
} else {
- // remove the non-PHP 5.4 version when PHP 5.3 support is dropped
- // as the non-optimized version is just a workaround for slow ternary operator
- // when the context has a lot of variables
- if (version_compare(phpversion(), '5.4.0RC1', '>=')) {
+ if (PHP_VERSION_ID >= 70000) {
+ // use PHP 7 null coalescing operator
+ $compiler
+ ->raw('($context[')
+ ->string($name)
+ ->raw('] ?? ')
+ ;
+
+ if ($this->getAttribute('ignore_strict_check') || !$compiler->getEnvironment()->isStrictVariables()) {
+ $compiler->raw('null)');
+ } else {
+ $compiler->raw('$this->getContext($context, ')->string($name)->raw('))');
+ }
+ } elseif (PHP_VERSION_ID >= 50400) {
// PHP 5.4 ternary operator performance was optimized
$compiler
->raw('(isset($context[')
@@ -86,3 +98,5 @@ class Twig_Node_Expression_Name extends Twig_Node_Expression
return !$this->isSpecial() && !$this->getAttribute('is_defined_test');
}
}
+
+class_alias('Twig_Node_Expression_Name', 'Twig\Node\Expression\NameExpression', false);
diff --git a/inc/lib/Twig/Node/Expression/NullCoalesce.php b/inc/lib/Twig/Node/Expression/NullCoalesce.php
new file mode 100644
index 00000000..eaafa4c9
--- /dev/null
+++ b/inc/lib/Twig/Node/Expression/NullCoalesce.php
@@ -0,0 +1,48 @@
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) Fabien Potencier
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+class Twig_Node_Expression_NullCoalesce extends Twig_Node_Expression_Conditional
+{
+ public function __construct(Twig_NodeInterface $left, Twig_NodeInterface $right, $lineno)
+ {
+ $test = new Twig_Node_Expression_Binary_And(
+ new Twig_Node_Expression_Test_Defined(clone $left, 'defined', new Twig_Node(), $left->getTemplateLine()),
+ new Twig_Node_Expression_Unary_Not(new Twig_Node_Expression_Test_Null($left, 'null', new Twig_Node(), $left->getTemplateLine()), $left->getTemplateLine()),
+ $left->getTemplateLine()
+ );
+
+ parent::__construct($test, $left, $right, $lineno);
+ }
+
+ public function compile(Twig_Compiler $compiler)
+ {
+ /*
+ * This optimizes only one case. PHP 7 also supports more complex expressions
+ * that can return null. So, for instance, if log is defined, log("foo") ?? "..." works,
+ * but log($a["foo"]) ?? "..." does not if $a["foo"] is not defined. More advanced
+ * cases might be implemented as an optimizer node visitor, but has not been done
+ * as benefits are probably not worth the added complexity.
+ */
+ if (PHP_VERSION_ID >= 70000 && $this->getNode('expr2') instanceof Twig_Node_Expression_Name) {
+ $this->getNode('expr2')->setAttribute('always_defined', true);
+ $compiler
+ ->raw('((')
+ ->subcompile($this->getNode('expr2'))
+ ->raw(') ?? (')
+ ->subcompile($this->getNode('expr3'))
+ ->raw('))')
+ ;
+ } else {
+ parent::compile($compiler);
+ }
+ }
+}
+
+class_alias('Twig_Node_Expression_NullCoalesce', 'Twig\Node\Expression\NullCoalesceExpression', false);
diff --git a/inc/lib/Twig/Node/Expression/Parent.php b/inc/lib/Twig/Node/Expression/Parent.php
index dcf618c0..78692db2 100644
--- a/inc/lib/Twig/Node/Expression/Parent.php
+++ b/inc/lib/Twig/Node/Expression/Parent.php
@@ -3,8 +3,8 @@
/*
* 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.
@@ -22,26 +22,23 @@ class Twig_Node_Expression_Parent extends Twig_Node_Expression
parent::__construct(array(), array('output' => false, 'name' => $name), $lineno, $tag);
}
- /**
- * Compiles the node to PHP.
- *
- * @param Twig_Compiler A Twig_Compiler instance
- */
public function compile(Twig_Compiler $compiler)
{
if ($this->getAttribute('output')) {
$compiler
->addDebugInfo($this)
- ->write("\$this->displayParentBlock(")
+ ->write('$this->displayParentBlock(')
->string($this->getAttribute('name'))
->raw(", \$context, \$blocks);\n")
;
} else {
$compiler
- ->raw("\$this->renderParentBlock(")
+ ->raw('$this->renderParentBlock(')
->string($this->getAttribute('name'))
- ->raw(", \$context, \$blocks)")
+ ->raw(', $context, $blocks)')
;
}
}
}
+
+class_alias('Twig_Node_Expression_Parent', 'Twig\Node\Expression\ParentExpression', false);
diff --git a/inc/lib/Twig/Node/Expression/TempName.php b/inc/lib/Twig/Node/Expression/TempName.php
index e6b058e8..0a86e003 100644
--- a/inc/lib/Twig/Node/Expression/TempName.php
+++ b/inc/lib/Twig/Node/Expression/TempName.php
@@ -3,7 +3,7 @@
/*
* This file is part of Twig.
*
- * (c) 2011 Fabien Potencier
+ * (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -24,3 +24,5 @@ class Twig_Node_Expression_TempName extends Twig_Node_Expression
;
}
}
+
+class_alias('Twig_Node_Expression_TempName', 'Twig\Node\Expression\TempNameExpression', false);
diff --git a/inc/lib/Twig/Node/Expression/Test.php b/inc/lib/Twig/Node/Expression/Test.php
index 639f501a..ad102ba6 100644
--- a/inc/lib/Twig/Node/Expression/Test.php
+++ b/inc/lib/Twig/Node/Expression/Test.php
@@ -3,7 +3,7 @@
/*
* This file is part of Twig.
*
- * (c) 2010 Fabien Potencier
+ * (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -12,7 +12,12 @@ class Twig_Node_Expression_Test extends Twig_Node_Expression_Call
{
public function __construct(Twig_NodeInterface $node, $name, Twig_NodeInterface $arguments = null, $lineno)
{
- parent::__construct(array('node' => $node, 'arguments' => $arguments), array('name' => $name), $lineno);
+ $nodes = array('node' => $node);
+ if (null !== $arguments) {
+ $nodes['arguments'] = $arguments;
+ }
+
+ parent::__construct($nodes, array('name' => $name), $lineno);
}
public function compile(Twig_Compiler $compiler)
@@ -26,7 +31,12 @@ class Twig_Node_Expression_Test extends Twig_Node_Expression_Call
if ($test instanceof Twig_TestCallableInterface || $test instanceof Twig_SimpleTest) {
$this->setAttribute('callable', $test->getCallable());
}
+ if ($test instanceof Twig_SimpleTest) {
+ $this->setAttribute('is_variadic', $test->isVariadic());
+ }
$this->compileCallable($compiler);
}
}
+
+class_alias('Twig_Node_Expression_Test', 'Twig\Node\Expression\TestExpression', false);
diff --git a/inc/lib/Twig/Node/Expression/Test/Constant.php b/inc/lib/Twig/Node/Expression/Test/Constant.php
index de55f5f5..a51a4ba1 100644
--- a/inc/lib/Twig/Node/Expression/Test/Constant.php
+++ b/inc/lib/Twig/Node/Expression/Test/Constant.php
@@ -3,7 +3,7 @@
/*
* This file is part of Twig.
*
- * (c) 2011 Fabien Potencier
+ * (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -44,3 +44,5 @@ class Twig_Node_Expression_Test_Constant extends Twig_Node_Expression_Test
;
}
}
+
+class_alias('Twig_Node_Expression_Test_Constant', 'Twig\Node\Expression\Test\ConstantTest', false);
diff --git a/inc/lib/Twig/Node/Expression/Test/Defined.php b/inc/lib/Twig/Node/Expression/Test/Defined.php
index 247b2e23..2136c390 100644
--- a/inc/lib/Twig/Node/Expression/Test/Defined.php
+++ b/inc/lib/Twig/Node/Expression/Test/Defined.php
@@ -3,7 +3,7 @@
/*
* This file is part of Twig.
*
- * (c) 2011 Fabien Potencier
+ * (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -25,17 +25,22 @@ class Twig_Node_Expression_Test_Defined extends Twig_Node_Expression_Test
{
public function __construct(Twig_NodeInterface $node, $name, Twig_NodeInterface $arguments = null, $lineno)
{
- parent::__construct($node, $name, $arguments, $lineno);
-
if ($node instanceof Twig_Node_Expression_Name) {
$node->setAttribute('is_defined_test', true);
} elseif ($node instanceof Twig_Node_Expression_GetAttr) {
$node->setAttribute('is_defined_test', true);
-
$this->changeIgnoreStrictCheck($node);
+ } elseif ($node instanceof Twig_Node_Expression_BlockReference) {
+ $node->setAttribute('is_defined_test', true);
+ } elseif ($node instanceof Twig_Node_Expression_Function && 'constant' === $node->getAttribute('name')) {
+ $node->setAttribute('is_defined_test', true);
+ } elseif ($node instanceof Twig_Node_Expression_Constant || $node instanceof Twig_Node_Expression_Array) {
+ $node = new Twig_Node_Expression_Constant(true, $node->getTemplateLine());
} else {
- throw new Twig_Error_Syntax('The "defined" test only works with simple variables', $this->getLine());
+ throw new Twig_Error_Syntax('The "defined" test only works with simple variables.', $this->getTemplateLine());
}
+
+ parent::__construct($node, $name, $arguments, $lineno);
}
protected function changeIgnoreStrictCheck(Twig_Node_Expression_GetAttr $node)
@@ -52,3 +57,5 @@ class Twig_Node_Expression_Test_Defined extends Twig_Node_Expression_Test
$compiler->subcompile($this->getNode('node'));
}
}
+
+class_alias('Twig_Node_Expression_Test_Defined', 'Twig\Node\Expression\Test\DefinedTest', false);
diff --git a/inc/lib/Twig/Node/Expression/Test/Divisibleby.php b/inc/lib/Twig/Node/Expression/Test/Divisibleby.php
index 0aceb530..a5d71961 100644
--- a/inc/lib/Twig/Node/Expression/Test/Divisibleby.php
+++ b/inc/lib/Twig/Node/Expression/Test/Divisibleby.php
@@ -3,7 +3,7 @@
/*
* This file is part of Twig.
*
- * (c) 2011 Fabien Potencier
+ * (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -13,7 +13,7 @@
* Checks if a variable is divisible by a number.
*
* <pre>
- * {% if loop.index is divisibleby(3) %}
+ * {% if loop.index is divisible by(3) %}
* </pre>
*
* @author Fabien Potencier <fabien@symfony.com>
@@ -31,3 +31,5 @@ class Twig_Node_Expression_Test_Divisibleby extends Twig_Node_Expression_Test
;
}
}
+
+class_alias('Twig_Node_Expression_Test_Divisibleby', 'Twig\Node\Expression\Test\DivisiblebyTest', false);
diff --git a/inc/lib/Twig/Node/Expression/Test/Even.php b/inc/lib/Twig/Node/Expression/Test/Even.php
index d7853e89..7e198bea 100644
--- a/inc/lib/Twig/Node/Expression/Test/Even.php
+++ b/inc/lib/Twig/Node/Expression/Test/Even.php
@@ -3,7 +3,7 @@
/*
* This file is part of Twig.
*
- * (c) 2011 Fabien Potencier
+ * (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -30,3 +30,5 @@ class Twig_Node_Expression_Test_Even extends Twig_Node_Expression_Test
;
}
}
+
+class_alias('Twig_Node_Expression_Test_Even', 'Twig\Node\Expression\Test\EvenTest', false);
diff --git a/inc/lib/Twig/Node/Expression/Test/Null.php b/inc/lib/Twig/Node/Expression/Test/Null.php
index 1c83825a..3746e4cb 100644
--- a/inc/lib/Twig/Node/Expression/Test/Null.php
+++ b/inc/lib/Twig/Node/Expression/Test/Null.php
@@ -3,7 +3,7 @@
/*
* This file is part of Twig.
*
- * (c) 2011 Fabien Potencier
+ * (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -29,3 +29,5 @@ class Twig_Node_Expression_Test_Null extends Twig_Node_Expression_Test
;
}
}
+
+class_alias('Twig_Node_Expression_Test_Null', 'Twig\Node\Expression\Test\NullTest', false);
diff --git a/inc/lib/Twig/Node/Expression/Test/Odd.php b/inc/lib/Twig/Node/Expression/Test/Odd.php
index 421c19e8..0c6c099b 100644
--- a/inc/lib/Twig/Node/Expression/Test/Odd.php
+++ b/inc/lib/Twig/Node/Expression/Test/Odd.php
@@ -3,7 +3,7 @@
/*
* This file is part of Twig.
*
- * (c) 2011 Fabien Potencier
+ * (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -30,3 +30,5 @@ class Twig_Node_Expression_Test_Odd extends Twig_Node_Expression_Test
;
}
}
+
+class_alias('Twig_Node_Expression_Test_Odd', 'Twig\Node\Expression\Test\OddTest', false);
diff --git a/inc/lib/Twig/Node/Expression/Test/Sameas.php b/inc/lib/Twig/Node/Expression/Test/Sameas.php
index b48905ee..e95ff1f2 100644
--- a/inc/lib/Twig/Node/Expression/Test/Sameas.php
+++ b/inc/lib/Twig/Node/Expression/Test/Sameas.php
@@ -3,7 +3,7 @@
/*
* This file is part of Twig.
*
- * (c) 2011 Fabien Potencier
+ * (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -27,3 +27,5 @@ class Twig_Node_Expression_Test_Sameas extends Twig_Node_Expression_Test
;
}
}
+
+class_alias('Twig_Node_Expression_Test_Sameas', 'Twig\Node\Expression\Test\SameasTest', false);
diff --git a/inc/lib/Twig/Node/Expression/Unary.php b/inc/lib/Twig/Node/Expression/Unary.php
index c514388e..5804485e 100644
--- a/inc/lib/Twig/Node/Expression/Unary.php
+++ b/inc/lib/Twig/Node/Expression/Unary.php
@@ -3,8 +3,8 @@
/*
* 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.
@@ -18,13 +18,12 @@ abstract class Twig_Node_Expression_Unary extends Twig_Node_Expression
public function compile(Twig_Compiler $compiler)
{
- $compiler->raw('(');
+ $compiler->raw(' ');
$this->operator($compiler);
- $compiler
- ->subcompile($this->getNode('node'))
- ->raw(')')
- ;
+ $compiler->subcompile($this->getNode('node'));
}
abstract public function operator(Twig_Compiler $compiler);
}
+
+class_alias('Twig_Node_Expression_Unary', 'Twig\Node\Expression\Unary\AbstractUnary', false);
diff --git a/inc/lib/Twig/Node/Expression/Unary/Neg.php b/inc/lib/Twig/Node/Expression/Unary/Neg.php
index 2a3937ec..039d933d 100644
--- a/inc/lib/Twig/Node/Expression/Unary/Neg.php
+++ b/inc/lib/Twig/Node/Expression/Unary/Neg.php
@@ -3,8 +3,8 @@
/*
* 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.
@@ -16,3 +16,5 @@ class Twig_Node_Expression_Unary_Neg extends Twig_Node_Expression_Unary
$compiler->raw('-');
}
}
+
+class_alias('Twig_Node_Expression_Unary_Neg', 'Twig\Node\Expression\Unary\NegUnary', false);
diff --git a/inc/lib/Twig/Node/Expression/Unary/Not.php b/inc/lib/Twig/Node/Expression/Unary/Not.php
index f94073cf..a0860b18 100644
--- a/inc/lib/Twig/Node/Expression/Unary/Not.php
+++ b/inc/lib/Twig/Node/Expression/Unary/Not.php
@@ -3,8 +3,8 @@
/*
* 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.
@@ -16,3 +16,5 @@ class Twig_Node_Expression_Unary_Not extends Twig_Node_Expression_Unary
$compiler->raw('!');
}
}
+
+class_alias('Twig_Node_Expression_Unary_Not', 'Twig\Node\Expression\Unary\NotUnary', false);
diff --git a/inc/lib/Twig/Node/Expression/Unary/Pos.php b/inc/lib/Twig/Node/Expression/Unary/Pos.php
index 04edb52a..eeff5452 100644
--- a/inc/lib/Twig/Node/Expression/Unary/Pos.php
+++ b/inc/lib/Twig/Node/Expression/Unary/Pos.php
@@ -3,8 +3,8 @@
/*
* 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.
@@ -16,3 +16,5 @@ class Twig_Node_Expression_Unary_Pos extends Twig_Node_Expression_Unary
$compiler->raw('+');
}
}
+
+class_alias('Twig_Node_Expression_Unary_Pos', 'Twig\Node\Expression\Unary\PosUnary', false);