From 9117fc1ce003388fb645ed984678770333faaebf Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 1 Nov 2011 11:49:04 +0100 Subject: [PATCH] added Twig_Function_Node to allow more complex functions to have their own Node class --- CHANGELOG | 1 + lib/Twig/ExpressionParser.php | 9 ++++++++- lib/Twig/Function/Node.php | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletions(-) create mode 100644 lib/Twig/Function/Node.php diff --git a/CHANGELOG b/CHANGELOG index 40b99c7..3dfa190 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * 1.4.0 + * added Twig_Function_Node to allow more complex functions to have their own Node class * added Twig_Filter_Node to allow more complex filters to have their own Node class * added Twig_Test_Node to allow more complex tests to have their own Node class * added a better error message when a template is empty but contain a BOM diff --git a/lib/Twig/ExpressionParser.php b/lib/Twig/ExpressionParser.php index c1e384e..af96e98 100644 --- a/lib/Twig/ExpressionParser.php +++ b/lib/Twig/ExpressionParser.php @@ -259,7 +259,14 @@ 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); } - return new Twig_Node_Expression_Function($name, $args, $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'; + } + + return new $class($name, $args, $line); } } diff --git a/lib/Twig/Function/Node.php b/lib/Twig/Function/Node.php new file mode 100644 index 0000000..a687a84 --- /dev/null +++ b/lib/Twig/Function/Node.php @@ -0,0 +1,37 @@ + + */ +class Twig_Function_Node extends Twig_Filter +{ + protected $class; + + public function __construct($class, array $options = array()) + { + parent::__construct($options); + + $this->class = $class; + } + + public function getClass() + { + return $this->class; + } + + public function compile() + { + } +} -- 1.7.2.5