function StackedKernelPass::processValue

File

core/lib/Drupal/Core/DependencyInjection/Compiler/StackedKernelPass.php, line 88

Class

StackedKernelPass
Provides a compiler pass for stacked HTTP kernels.

Namespace

Drupal\Core\DependencyInjection\Compiler

Code

protected function processValue(mixed $value, bool $isRoot = FALSE) : mixed {
  $value = parent::processValue($value, $isRoot);
  if (!$value instanceof Definition || !$value->hasTag('http_middleware')) {
    return $value;
  }
  $constructor = $this->getConstructor($value, TRUE);
  $params = $constructor->getParameters();
  $innerType = $params[0]->getType();
  $innerParamTypes = $innerType instanceof \ReflectionUnionType || $innerType instanceof \ReflectionIntersectionType ? $innerType->getTypes() : [
    $innerType,
  ];
  $paramTypeNames = array_map(fn($param) => (string) $param, $innerParamTypes);
  $inner = new Reference($this->currentId . '.http_middleware_inner');
  if (in_array(\Closure::class, $paramTypeNames, TRUE)) {
    $inner = new ServiceClosureArgument($inner);
  }
  $arguments = $value->getArguments();
  array_unshift($arguments, $inner);
  $value->setArguments($arguments);
  return $value;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.