diff --git a/lib/Twig/ExpressionParser.php b/lib/Twig/ExpressionParser.php index 135958a35..085588c27 100644 --- a/lib/Twig/ExpressionParser.php +++ b/lib/Twig/ExpressionParser.php @@ -578,6 +578,16 @@ class Twig_ExpressionParser 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 @@ class Twig_ExpressionParser 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 5d6d27bf2..cefc4f587 100644 --- a/lib/Twig/SimpleFilter.php +++ b/lib/Twig/SimpleFilter.php @@ -34,6 +34,8 @@ class Twig_SimpleFilter 'pre_escape' => null, 'preserves_safety' => null, 'node_class' => 'Twig_Node_Expression_Filter', + 'deprecated' => false, + 'alternative' => null, ), $options); } @@ -97,4 +99,14 @@ class Twig_SimpleFilter { 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 8085f5788..79735405c 100644 --- a/lib/Twig/SimpleFunction.php +++ b/lib/Twig/SimpleFunction.php @@ -32,6 +32,8 @@ class Twig_SimpleFunction 'is_safe' => null, 'is_safe_callback' => null, 'node_class' => 'Twig_Node_Expression_Function', + 'deprecated' => false, + 'alternative' => null, ), $options); } @@ -87,4 +89,14 @@ class Twig_SimpleFunction { return $this->options['is_variadic']; } + + public function isDeprecated() + { + return $this->options['deprecated']; + } + + public function getAlternative() + { + return $this->options['alternative']; + } }