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);
}
$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);
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';
+ }
}
$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';
}
/**