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

Breadcrumb

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

function InlineServiceDefinitionsPass::isInlineableDefinition

Checks if the definition is inlineable.

1 call to InlineServiceDefinitionsPass::isInlineableDefinition()
InlineServiceDefinitionsPass::processValue in vendor/symfony/dependency-injection/Compiler/InlineServiceDefinitionsPass.php
Processes a value found in a definition tree.

File

vendor/symfony/dependency-injection/Compiler/InlineServiceDefinitionsPass.php, line 166

Class

InlineServiceDefinitionsPass
Inline service definitions where this is possible.

Namespace

Symfony\Component\DependencyInjection\Compiler

Code

private function isInlineableDefinition(string $id, Definition $definition) : bool {
    if (str_starts_with($id, '.autowire_inline.')) {
        return true;
    }
    if ($definition->hasErrors() || $definition->isDeprecated() || $definition->isLazy() || $definition->isSynthetic() || $definition->hasTag('container.do_not_inline')) {
        return false;
    }
    if (!$definition->isShared()) {
        if (!$this->graph
            ->hasNode($id)) {
            return true;
        }
        foreach ($this->graph
            ->getNode($id)
            ->getInEdges() as $edge) {
            $srcId = $edge->getSourceNode()
                ->getId();
            $this->connectedIds[$srcId] = true;
            if ($edge->isWeak() || $edge->isLazy()) {
                return !($this->connectedIds[$id] = true);
            }
        }
        return true;
    }
    if ($definition->isPublic()) {
        return false;
    }
    if (!$this->graph
        ->hasNode($id)) {
        return true;
    }
    if ($this->currentId === $id) {
        return false;
    }
    $this->connectedIds[$id] = true;
    $srcIds = [];
    $srcCount = 0;
    foreach ($this->graph
        ->getNode($id)
        ->getInEdges() as $edge) {
        $srcId = $edge->getSourceNode()
            ->getId();
        $this->connectedIds[$srcId] = true;
        if ($edge->isWeak() || $edge->isLazy()) {
            return false;
        }
        $srcIds[$srcId] = true;
        ++$srcCount;
    }
    if (1 !== \count($srcIds)) {
        $this->notInlinedIds[$id] = true;
        return false;
    }
    if ($srcCount > 1 && \is_array($factory = $definition->getFactory()) && ($factory[0] instanceof Reference || $factory[0] instanceof Definition)) {
        return false;
    }
    return $this->container
        ->getDefinition($srcId)
        ->isShared();
}
RSS feed
Powered by Drupal