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

Breadcrumb

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

function PhpDumper::addServiceInclude

1 call to PhpDumper::addServiceInclude()
PhpDumper::addService in vendor/symfony/dependency-injection/Dumper/PhpDumper.php

File

vendor/symfony/dependency-injection/Dumper/PhpDumper.php, line 626

Class

PhpDumper
PhpDumper dumps a service container as a PHP class.

Namespace

Symfony\Component\DependencyInjection\Dumper

Code

private function addServiceInclude(string $cId, Definition $definition, bool $isProxyCandidate) : string {
    $code = '';
    if ($this->inlineRequires && (!$this->isHotPath($definition) || $isProxyCandidate)) {
        $lineage = [];
        foreach ($this->inlinedDefinitions as $def) {
            if (!$def->isDeprecated()) {
                foreach ($this->getClasses($def, $cId) as $class) {
                    $this->collectLineage($class, $lineage);
                }
            }
        }
        foreach ($this->serviceCalls as $id => [
            $callCount,
            $behavior,
        ]) {
            if ('service_container' !== $id && $id !== $cId && ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE !== $behavior && $this->container
                ->has($id) && $this->isTrivialInstance($def = $this->container
                ->findDefinition($id))) {
                foreach ($this->getClasses($def, $cId) as $class) {
                    $this->collectLineage($class, $lineage);
                }
            }
        }
        foreach (array_diff_key(array_flip($lineage), $this->inlinedRequires) as $file => $class) {
            $code .= \sprintf("        include_once %s;\n", $file);
        }
    }
    foreach ($this->inlinedDefinitions as $def) {
        if ($file = $def->getFile()) {
            $file = $this->dumpValue($file);
            $file = '(' === $file[0] ? substr($file, 1, -1) : $file;
            $code .= \sprintf("        include_once %s;\n", $file);
        }
    }
    if ('' !== $code) {
        $code .= "\n";
    }
    return $code;
}
RSS feed
Powered by Drupal