summaryrefslogtreecommitdiff
path: root/inc/lib/Twig/Node/Expression
diff options
context:
space:
mode:
Diffstat (limited to 'inc/lib/Twig/Node/Expression')
-rw-r--r--inc/lib/Twig/Node/Expression/Call.php6
-rw-r--r--inc/lib/Twig/Node/Expression/GetAttr.php4
-rw-r--r--inc/lib/Twig/Node/Expression/MacroCall.php60
3 files changed, 65 insertions, 5 deletions
diff --git a/inc/lib/Twig/Node/Expression/Call.php b/inc/lib/Twig/Node/Expression/Call.php
index 87b62deb..dba9b0e6 100644
--- a/inc/lib/Twig/Node/Expression/Call.php
+++ b/inc/lib/Twig/Node/Expression/Call.php
@@ -146,7 +146,7 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression
if (array_key_exists($name, $parameters)) {
if (array_key_exists($pos, $parameters)) {
- throw new Twig_Error_Syntax(sprintf('Arguments "%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, $this->getAttribute('type'), $this->getAttribute('name')));
}
$arguments[] = $parameters[$name];
@@ -164,8 +164,8 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression
}
}
- foreach (array_keys($parameters) as $name) {
- throw new Twig_Error_Syntax(sprintf('Unknown argument "%s" for %s "%s".', $name, $this->getAttribute('type'), $this->getAttribute('name')));
+ 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')));
}
return $arguments;
diff --git a/inc/lib/Twig/Node/Expression/GetAttr.php b/inc/lib/Twig/Node/Expression/GetAttr.php
index 81a9b137..55d9fcc3 100644
--- a/inc/lib/Twig/Node/Expression/GetAttr.php
+++ b/inc/lib/Twig/Node/Expression/GetAttr.php
@@ -32,10 +32,10 @@ class Twig_Node_Expression_GetAttr extends Twig_Node_Expression
$compiler->raw(', ')->subcompile($this->getNode('attribute'));
- if (count($this->getNode('arguments')) || Twig_TemplateInterface::ANY_CALL !== $this->getAttribute('type') || $this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) {
+ 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'));
- if (Twig_TemplateInterface::ANY_CALL !== $this->getAttribute('type') || $this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) {
+ if (Twig_Template::ANY_CALL !== $this->getAttribute('type') || $this->getAttribute('is_defined_test') || $this->getAttribute('ignore_strict_check')) {
$compiler->raw(', ')->repr($this->getAttribute('type'));
}
diff --git a/inc/lib/Twig/Node/Expression/MacroCall.php b/inc/lib/Twig/Node/Expression/MacroCall.php
new file mode 100644
index 00000000..3e6b8c12
--- /dev/null
+++ b/inc/lib/Twig/Node/Expression/MacroCall.php
@@ -0,0 +1,60 @@
+<?php
+
+/*
+ * This file is part of Twig.
+ *
+ * (c) 2012 Fabien Potencier
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Represents a macro call node.
+ *
+ * @author Martin HasoĊˆ <martin.hason@gmail.com>
+ */
+class Twig_Node_Expression_MacroCall extends Twig_Node_Expression
+{
+ public function __construct(Twig_Node_Expression $template, $name, Twig_Node_Expression_Array $arguments, $lineno)
+ {
+ parent::__construct(array('template' => $template, 'arguments' => $arguments), array('name' => $name), $lineno);
+ }
+
+ public function compile(Twig_Compiler $compiler)
+ {
+ $namedNames = array();
+ $namedCount = 0;
+ $positionalCount = 0;
+ foreach ($this->getNode('arguments')->getKeyValuePairs() as $pair) {
+ $name = $pair['key']->getAttribute('value');
+ if (!is_int($name)) {
+ $namedCount++;
+ $namedNames[$name] = 1;
+ } elseif ($namedCount > 0) {
+ throw new Twig_Error_Syntax(sprintf('Positional arguments cannot be used after named arguments for macro "%s".', $this->getAttribute('name')), $this->lineno);
+ } else {
+ $positionalCount++;
+ }
+ }
+
+ $compiler
+ ->raw('$this->callMacro(')
+ ->subcompile($this->getNode('template'))
+ ->raw(', ')->repr($this->getAttribute('name'))
+ ->raw(', ')->subcompile($this->getNode('arguments'))
+ ;
+
+ if ($namedCount > 0) {
+ $compiler
+ ->raw(', ')->repr($namedNames)
+ ->raw(', ')->repr($namedCount)
+ ->raw(', ')->repr($positionalCount)
+ ;
+ }
+
+ $compiler
+ ->raw(')')
+ ;
+ }
+}