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

Breadcrumb

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

function AnalyzeServiceReferencesPass::processValue

Overrides AbstractRecursivePass::processValue

File

vendor/symfony/dependency-injection/Compiler/AnalyzeServiceReferencesPass.php, line 81

Class

AnalyzeServiceReferencesPass
Run this pass before passes that need to know more about the relation of your services.

Namespace

Symfony\Component\DependencyInjection\Compiler

Code

protected function processValue(mixed $value, bool $isRoot = false) : mixed {
    $lazy = $this->lazy;
    $inExpression = $this->inExpression();
    if ($value instanceof ArgumentInterface) {
        $this->lazy = !$this->byFactory || !$value instanceof IteratorArgument;
        parent::processValue($value->getValues());
        $this->lazy = $lazy;
        return $value;
    }
    if ($value instanceof Reference) {
        $targetId = $this->getDefinitionId((string) $value);
        $targetDefinition = null !== $targetId ? $this->container
            ->getDefinition($targetId) : null;
        $this->graph
            ->connect($this->currentId, $this->currentDefinition, $targetId, $targetDefinition, $value, $this->lazy || $this->hasProxyDumper && $targetDefinition?->isLazy(), ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $value->getInvalidBehavior(), $this->byConstructor);
        if ($inExpression) {
            $this->graph
                ->connect('.internal.reference_in_expression', null, $targetId, $targetDefinition, $value, $this->lazy || $targetDefinition?->isLazy(), true);
        }
        return $value;
    }
    if (!$value instanceof Definition) {
        return parent::processValue($value, $isRoot);
    }
    if ($isRoot) {
        if ($value->isSynthetic() || $value->isAbstract()) {
            return $value;
        }
        $this->currentDefinition = $value;
    }
    elseif ($this->currentDefinition === $value) {
        return $value;
    }
    $this->lazy = false;
    $byConstructor = $this->byConstructor;
    $this->byConstructor = $isRoot || $byConstructor;
    $byFactory = $this->byFactory;
    $this->byFactory = true;
    if (\is_string($factory = $value->getFactory()) && str_starts_with($factory, '@=')) {
        if (!class_exists(Expression::class)) {
            throw new LogicException('Expressions cannot be used in service factories without the ExpressionLanguage component. Try running "composer require symfony/expression-language".');
        }
        $factory = new Expression(substr($factory, 2));
    }
    $this->processValue($factory);
    $this->byFactory = $byFactory;
    $this->processValue($value->getArguments());
    $properties = $value->getProperties();
    $setters = $value->getMethodCalls();
    // Any references before a "wither" are part of the constructor-instantiation graph
    $lastWitherIndex = null;
    foreach ($setters as $k => $call) {
        if ($call[2] ?? false) {
            $lastWitherIndex = $k;
        }
    }
    if (null !== $lastWitherIndex) {
        $this->processValue($properties);
        $setters = $properties = [];
        foreach ($value->getMethodCalls() as $k => $call) {
            if (null === $lastWitherIndex) {
                $setters[] = $call;
                continue;
            }
            if ($lastWitherIndex === $k) {
                $lastWitherIndex = null;
            }
            $this->processValue($call);
        }
    }
    $this->byConstructor = $byConstructor;
    if (!$this->onlyConstructorArguments) {
        $this->processValue($properties);
        $this->processValue($setters);
        $this->processValue($value->getConfigurator());
    }
    $this->lazy = $lazy;
    return $value;
}

API Navigation

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