From: Fabien Potencier Date: Thu, 1 Sep 2011 07:16:08 +0000 (+0200) Subject: made a markup refactoring X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=39774a1118be8de32879203d3033c43bc5469472;p=web%2Fkonrad%2Ftwig.git made a markup refactoring --- diff --git a/lib/Twig/ExpressionParser.php b/lib/Twig/ExpressionParser.php index d2e6ccf..b4fc5d5 100644 --- a/lib/Twig/ExpressionParser.php +++ b/lib/Twig/ExpressionParser.php @@ -235,36 +235,32 @@ class Twig_ExpressionParser public function getFunctionNode($name, $line) { $args = $this->parseArguments(); + switch ($name) { + case 'parent': + if (!count($this->parser->getBlockStack())) { + throw new Twig_Error_Syntax('Calling "parent" outside a block is forbidden', $line); + } - if ('parent' === $name) { - if (!count($this->parser->getBlockStack())) { - throw new Twig_Error_Syntax('Calling "parent" outside a block is forbidden', $line); - } - - if (!$this->parser->getParent()) { - throw new Twig_Error_Syntax('Calling "parent" on a template that does not extend another one is forbidden', $line); - } - - return new Twig_Node_Expression_Parent($this->parser->peekBlockStack(), $line); - } - - if ('block' === $name) { - return new Twig_Node_Expression_BlockReference($args->getNode(0), false, $line); - } + if (!$this->parser->getParent()) { + throw new Twig_Error_Syntax('Calling "parent" on a template that does not extend another one is forbidden', $line); + } - if ('attribute' === $name) { - if (count($args) < 2) { - throw new Twig_Error_Syntax('The "attribute" function takes at least two arguments (the variable and the attribute)', $line); - } + return new Twig_Node_Expression_Parent($this->parser->peekBlockStack(), $line); + case 'block': + return new Twig_Node_Expression_BlockReference($args->getNode(0), false, $line); + case 'attribute': + if (count($args) < 2) { + throw new Twig_Error_Syntax('The "attribute" function takes at least two arguments (the variable and the attribute)', $line); + } - return new Twig_Node_Expression_GetAttr($args->getNode(0), $args->getNode(1), count($args) > 2 ? $args->getNode(2) : new Twig_Node_Expression_Array(array(), $line), Twig_TemplateInterface::ANY_CALL, $line); - } + return new Twig_Node_Expression_GetAttr($args->getNode(0), $args->getNode(1), count($args) > 2 ? $args->getNode(2) : new Twig_Node_Expression_Array(array(), $line), Twig_TemplateInterface::ANY_CALL, $line); + default: + if (null !== $alias = $this->parser->getImportedFunction($name)) { + return new Twig_Node_Expression_GetAttr($alias['node'], new Twig_Node_Expression_Constant($alias['name'], $line), $args, Twig_TemplateInterface::METHOD_CALL, $line); + } - if (null !== $alias = $this->parser->getImportedFunction($name)) { - return new Twig_Node_Expression_GetAttr($alias['node'], new Twig_Node_Expression_Constant($alias['name'], $line), $args, Twig_TemplateInterface::METHOD_CALL, $line); + return new Twig_Node_Expression_Function($name, $args, $line); } - - return new Twig_Node_Expression_Function($name, $args, $line); } public function parseSubscriptExpression($node)