From: Fabien Potencier Date: Tue, 1 Nov 2011 10:49:04 +0000 (+0100) Subject: added Twig_Function_Node to allow more complex functions to have their own Node class X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=9117fc1ce003388fb645ed984678770333faaebf;p=web%2Fkonrad%2Ftwig.git added Twig_Function_Node to allow more complex functions to have their own Node class --- 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() + { + } +}