Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. CallExpression.php

function CallExpression::getCallableParameters

1 call to CallExpression::getCallableParameters()
CallExpression::getArguments in vendor/twig/twig/src/Node/Expression/CallExpression.php

File

vendor/twig/twig/src/Node/Expression/CallExpression.php, line 271

Class

CallExpression

Namespace

Twig\Node\Expression

Code

private function getCallableParameters($callable, bool $isVariadic) : array {
    $twigCallable = $this->getAttribute('twig_callable');
    $rc = $this->reflectCallable($twigCallable);
    $r = $rc->getReflector();
    $callableName = $rc->getName();
    $parameters = $r->getParameters();
    if ($this->hasNode('node')) {
        array_shift($parameters);
    }
    if ($twigCallable->needsCharset()) {
        array_shift($parameters);
    }
    if ($twigCallable->needsEnvironment()) {
        array_shift($parameters);
    }
    if ($twigCallable->needsContext()) {
        array_shift($parameters);
    }
    foreach ($twigCallable->getArguments() as $argument) {
        array_shift($parameters);
    }
    $isPhpVariadic = false;
    if ($isVariadic) {
        $argument = end($parameters);
        $isArray = $argument && $argument->hasType() && $argument->getType() instanceof \ReflectionNamedType && 'array' === $argument->getType()
            ->getName();
        if ($isArray && $argument->isDefaultValueAvailable() && [] === $argument->getDefaultValue()) {
            array_pop($parameters);
        }
        elseif ($argument && $argument->isVariadic()) {
            array_pop($parameters);
            $isPhpVariadic = true;
        }
        else {
            throw new \LogicException(\sprintf('The last parameter of "%s" for %s "%s" must be an array with default value, eg. "array $arg = []".', $callableName, $this->getAttribute('type'), $twigCallable->getName()));
        }
    }
    return [
        $parameters,
        $isPhpVariadic,
    ];
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal