From: Fabien Potencier Date: Tue, 1 Nov 2011 10:54:32 +0000 (+0100) Subject: refactored code X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=103e85729021d557e9cf389a9b5408bc5a1651e4;p=web%2Fkonrad%2Ftwig.git refactored code --- diff --git a/lib/Twig/ExpressionParser.php b/lib/Twig/ExpressionParser.php index af96e98..33cc0dc 100644 --- a/lib/Twig/ExpressionParser.php +++ b/lib/Twig/ExpressionParser.php @@ -259,12 +259,7 @@ class Twig_ExpressionParser return new Twig_Node_Expression_GetAttr($alias['node'], new Twig_Node_Expression_Constant($alias['name'], $line), $args, Twig_TemplateInterface::METHOD_CALL, $line); } - $functionMap = $this->parser->getEnvironment()->getFunctions(); - if (isset($functionMap[$name]) && $functionMap[$name] instanceof Twig_Filter_Node) { - $class = $functionMap[$name]->getClass(); - } else { - $class = 'Twig_Node_Expression_Function'; - } + $class = $this->getFunctionNodeClass($name); return new $class($name, $args, $line); } @@ -325,12 +320,7 @@ class Twig_ExpressionParser $arguments = $this->parseArguments(); } - $filterMap = $this->parser->getEnvironment()->getFilters(); - if (isset($filterMap[$name->getAttribute('value')]) && $filterMap[$name->getAttribute('value')] instanceof Twig_Filter_Node) { - $class = $filterMap[$name->getAttribute('value')]->getClass(); - } else { - $class = 'Twig_Node_Expression_Filter'; - } + $class = $this->getFilterNodeClass($name->getAttribute('value')); $node = new $class($node, $name, $arguments, $token->getLine(), $tag); @@ -393,4 +383,24 @@ class Twig_ExpressionParser return new Twig_Node($targets); } + + protected function getFunctionNodeClass($name) + { + $functionMap = $this->parser->getEnvironment()->getFunctions(); + if (isset($functionMap[$name]) && $functionMap[$name] instanceof Twig_Filter_Node) { + return $functionMap[$name]->getClass(); + } + + return 'Twig_Node_Expression_Function'; + } + + protected function getFilterNodeClass($name) + { + $filterMap = $this->parser->getEnvironment()->getFilters(); + if (isset($filterMap[$name]) && $filterMap[$name] instanceof Twig_Filter_Node) { + return $filterMap[$name]->getClass(); + } + + return 'Twig_Node_Expression_Filter'; + } } diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index 5e5fdee..465818d 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -178,14 +178,19 @@ class Twig_Extension_Core extends Twig_Extension $arguments = $parser->getExpressionParser()->parseArguments(); } - $testMap = $parser->getEnvironment()->getTests(); + $class = $this->getTestNodeClass($parser->getEnvironment(), $name); + + return new $class($node, $name, $arguments, $parser->getCurrentToken()->getLine()); + } + + protected function getTestNodeClass(Twig_Environment $env, $name) + { + $testMap = $env->getTests(); if (isset($testMap[$name]) && $testMap[$name] instanceof Twig_Test_Node) { - $class = $testMap[$name]->getClass(); - } else { - $class = 'Twig_Node_Expression_Test'; + return $testMap[$name]->getClass(); } - return new $class($node, $name, $arguments, $parser->getCurrentToken()->getLine()); + return 'Twig_Node_Expression_Test'; } /**