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

Breadcrumb

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

function AutowirePass::doProcessValue

2 calls to AutowirePass::doProcessValue()
AutowirePass::autowireMethod in vendor/symfony/dependency-injection/Compiler/AutowirePass.php
Autowires the constructor or a method.
AutowirePass::processValue in vendor/symfony/dependency-injection/Compiler/AutowirePass.php
Processes a value found in a definition tree.

File

vendor/symfony/dependency-injection/Compiler/AutowirePass.php, line 110

Class

AutowirePass
Inspects existing service definitions and wires the autowired ones using the type hints of their classes.

Namespace

Symfony\Component\DependencyInjection\Compiler

Code

private function doProcessValue(mixed $value, bool $isRoot = false) : mixed {
    if ($value instanceof TypedReference) {
        foreach ($value->getAttributes() as $attribute) {
            if ($attribute === ($v = $this->processValue($attribute))) {
                continue;
            }
            if (!$attribute instanceof Autowire || !$v instanceof Reference) {
                return $v;
            }
            $invalidBehavior = ContainerBuilder::EXCEPTION_ON_INVALID_REFERENCE !== $v->getInvalidBehavior() ? $v->getInvalidBehavior() : $value->getInvalidBehavior();
            $value = $v instanceof TypedReference ? new TypedReference($v, $v->getType(), $invalidBehavior, $v->getName() ?? $value->getName(), array_merge($v->getAttributes(), $value->getAttributes())) : new TypedReference($v, $value->getType(), $invalidBehavior, $value->getName(), $value->getAttributes());
            break;
        }
        if ($ref = $this->getAutowiredReference($value, true)) {
            return $ref;
        }
        if (ContainerBuilder::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE === $value->getInvalidBehavior()) {
            $message = $this->createTypeNotFoundMessageCallback($value, 'it');
            // since the error message varies by referenced id and $this->currentId, so should the id of the dummy errored definition
            $this->container
                ->register($id = \sprintf('.errored.%s.%s', $this->currentId, (string) $value), $value->getType())
                ->addError($message);
            return new TypedReference($id, $value->getType(), $value->getInvalidBehavior(), $value->getName());
        }
    }
    $value = parent::processValue($value, $isRoot);
    if (!$value instanceof Definition || !$value->isAutowired() || $value->isAbstract() || !$value->getClass()) {
        return $value;
    }
    if (!($reflectionClass = $this->container
        ->getReflectionClass($value->getClass(), false))) {
        $this->container
            ->log($this, \sprintf('Skipping service "%s": Class or interface "%s" cannot be loaded.', $this->currentId, $value->getClass()));
        return $value;
    }
    $methodCalls = $value->getMethodCalls();
    try {
        $constructor = $this->getConstructor($value, false);
    } catch (RuntimeException $e) {
        throw new AutowiringFailedException($this->currentId, $e->getMessage(), 0, $e);
    }
    if ($constructor) {
        array_unshift($methodCalls, [
            $constructor,
            $value->getArguments(),
        ]);
    }
    $checkAttributes = !$value->hasTag('container.ignore_attributes');
    $methodCalls = $this->autowireCalls($methodCalls, $reflectionClass, $isRoot, $checkAttributes);
    if ($constructor) {
        [
            ,
            $arguments,
        ] = array_shift($methodCalls);
        if ($arguments !== $value->getArguments()) {
            $value->setArguments($arguments);
        }
    }
    if ($methodCalls !== $value->getMethodCalls()) {
        $value->setMethodCalls($methodCalls);
    }
    return $value;
}

API Navigation

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