mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-15 11:56:50 +00:00
Fix the error handling for the optimized extension-based function calls
Triggering a Twig_Error_Runtime at compile-time breaks the contract of the Twig environment, as such exception is for errors during the rendering.
This commit is contained in:
@@ -31,10 +31,13 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression
|
||||
// For BC/FC with namespaced aliases
|
||||
$class = (new ReflectionClass(get_class($callable[0])))->name;
|
||||
if (!$compiler->getEnvironment()->hasExtension($class)) {
|
||||
throw new Twig_Error_Runtime(sprintf('The "%s" extension is not enabled.', $class));
|
||||
// Compile a non-optimized call to trigger a Twig_Error_Runtime, which cannot be a compile-time error
|
||||
$compiler->raw(sprintf('$this->env->getExtension(\'%s\')', $class));
|
||||
} else {
|
||||
$compiler->raw(sprintf('$this->extensions[\'%s\']', ltrim($class, '\\')));
|
||||
}
|
||||
|
||||
$compiler->raw(sprintf('$this->extensions[\'%s\']->%s', ltrim($class, '\\'), $callable[1]));
|
||||
$compiler->raw(sprintf('->%s', $callable[1]));
|
||||
} else {
|
||||
$closingParenthesis = true;
|
||||
$compiler->raw(sprintf('call_user_func_array($this->env->get%s(\'%s\')->getCallable(), array', ucfirst($this->getAttribute('type')), $this->getAttribute('name')));
|
||||
|
||||
Reference in New Issue
Block a user