From f4c5152f454d86438cb53af7fbcb15061df165b9 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 2 Mar 2018 10:56:39 -0800 Subject: [PATCH] optimized calls to custom extension runtimes --- lib/Twig/Node/Expression/Call.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/Twig/Node/Expression/Call.php b/lib/Twig/Node/Expression/Call.php index 727646fe6..3ba45e377 100644 --- a/lib/Twig/Node/Expression/Call.php +++ b/lib/Twig/Node/Expression/Call.php @@ -28,7 +28,13 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression $compiler->raw(sprintf('$this->env->getRuntime(\'%s\')->%s', $callable[0], $callable[1])); } } elseif ($r instanceof ReflectionMethod && $callable[0] instanceof Twig_ExtensionInterface) { - $compiler->raw(sprintf('$this->env->getExtension(\'%s\')->%s', get_class($callable[0]), $callable[1])); + // 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)); + } + + $compiler->raw(sprintf('$this->extensions[\'%s\']->%s', ltrim($class, '\\'), $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')));