function CallExpression::compileCallable
3 calls to CallExpression::compileCallable()
- FilterExpression::compile in vendor/
twig/ twig/ src/ Node/ Expression/ FilterExpression.php - FunctionExpression::compile in vendor/
twig/ twig/ src/ Node/ Expression/ FunctionExpression.php - TestExpression::compile in vendor/
twig/ twig/ src/ Node/ Expression/ TestExpression.php
File
-
vendor/
twig/ twig/ src/ Node/ Expression/ CallExpression.php, line 29
Class
Namespace
Twig\Node\ExpressionCode
protected function compileCallable(Compiler $compiler) {
$twigCallable = $this->getTwigCallable();
$callable = $twigCallable->getCallable();
if (\is_string($callable) && !str_contains($callable, '::')) {
$compiler->raw($callable);
}
else {
$rc = $this->reflectCallable($twigCallable);
$r = $rc->getReflector();
$callable = $rc->getCallable();
if (\is_string($callable)) {
$compiler->raw($callable);
}
elseif (\is_array($callable) && \is_string($callable[0])) {
if (!$r instanceof \ReflectionMethod || $r->isStatic()) {
$compiler->raw(\sprintf('%s::%s', $callable[0], $callable[1]));
}
else {
$compiler->raw(\sprintf('$this->env->getRuntime(\'%s\')->%s', $callable[0], $callable[1]));
}
}
elseif (\is_array($callable) && $callable[0] instanceof ExtensionInterface) {
$class = \get_class($callable[0]);
if (!$compiler->getEnvironment()
->hasExtension($class)) {
// Compile a non-optimized call to trigger a \Twig\Error\RuntimeError, 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('->%s', $callable[1]));
}
else {
$compiler->raw(\sprintf('$this->env->get%s(\'%s\')->getCallable()', ucfirst($this->getAttribute('type')), $twigCallable->getDynamicName()));
}
}
$this->compileArguments($compiler);
}