mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-14 11:27:00 +00:00
added a way to trigger deprecation notices for filters and functions
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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'];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user