diff --git a/lib/Twig/ExpressionParser.php b/lib/Twig/ExpressionParser.php index 135958a35a..085588c272 100644 --- a/lib/Twig/ExpressionParser.php +++ b/lib/Twig/ExpressionParser.php @@ -578,6 +578,16 @@ protected function getFunctionNodeClass($name, $line) throw new Twig_Error_Syntax($message, $line, $this->parser->getFilename()); } + if ($function instanceof Twig_SimpleFunction && $function->isDeprecated()) { + $message = sprintf('Twig Function "%s" is deprecated', $function->getName()); + if ($test->getAlternative()) { + $message .= sprintf('. Use "%s" instead', $function->getAlternative()); + } + $message .= sprintf(' in %s at line %d.', $this->parser->getFilename(), $line); + + @trigger_error($message, E_USER_DEPRECATED); + } + if ($function instanceof Twig_SimpleFunction) { return $function->getNodeClass(); } @@ -598,6 +608,16 @@ protected function getFilterNodeClass($name, $line) throw new Twig_Error_Syntax($message, $line, $this->parser->getFilename()); } + if ($filter instanceof Twig_SimpleFilter && $filter->isDeprecated()) { + $message = sprintf('Twig Filter "%s" is deprecated', $filter->getName()); + if ($test->getAlternative()) { + $message .= sprintf('. Use "%s" instead', $filter->getAlternative()); + } + $message .= sprintf(' in %s at line %d.', $this->parser->getFilename(), $line); + + @trigger_error($message, E_USER_DEPRECATED); + } + if ($filter instanceof Twig_SimpleFilter) { return $filter->getNodeClass(); } diff --git a/lib/Twig/SimpleFilter.php b/lib/Twig/SimpleFilter.php index 5d6d27bf2b..cefc4f587f 100644 --- a/lib/Twig/SimpleFilter.php +++ b/lib/Twig/SimpleFilter.php @@ -34,6 +34,8 @@ public function __construct($name, $callable, array $options = array()) 'pre_escape' => null, 'preserves_safety' => null, 'node_class' => 'Twig_Node_Expression_Filter', + 'deprecated' => false, + 'alternative' => null, ), $options); } @@ -97,4 +99,14 @@ public function isVariadic() { return $this->options['is_variadic']; } + + public function isDeprecated() + { + return $this->options['deprecated']; + } + + public function getAlternative() + { + return $this->options['alternative']; + } } diff --git a/lib/Twig/SimpleFunction.php b/lib/Twig/SimpleFunction.php index 8085f5788d..79735405cb 100644 --- a/lib/Twig/SimpleFunction.php +++ b/lib/Twig/SimpleFunction.php @@ -32,6 +32,8 @@ public function __construct($name, $callable, array $options = array()) 'is_safe' => null, 'is_safe_callback' => null, 'node_class' => 'Twig_Node_Expression_Function', + 'deprecated' => false, + 'alternative' => null, ), $options); } @@ -87,4 +89,14 @@ public function isVariadic() { return $this->options['is_variadic']; } + + public function isDeprecated() + { + return $this->options['deprecated']; + } + + public function getAlternative() + { + return $this->options['alternative']; + } }