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

Breadcrumb

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

function CheckExceptionOnInvalidReferenceBehaviorPass::throwServiceNotFoundException

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

File

vendor/symfony/dependency-injection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php, line 86

Class

CheckExceptionOnInvalidReferenceBehaviorPass
Checks that all references are pointing to a valid service.

Namespace

Symfony\Component\DependencyInjection\Compiler

Code

private function throwServiceNotFoundException(Reference $ref, string $sourceId, mixed $value) : void {
    $id = (string) $ref;
    $alternatives = [];
    foreach ($this->container
        ->getServiceIds() as $knownId) {
        if ('' === $knownId || '.' === $knownId[0] || $knownId === $this->currentId) {
            continue;
        }
        $lev = levenshtein($id, $knownId);
        if ($lev <= \strlen($id) / 3 || str_contains($knownId, $id)) {
            $alternatives[] = $knownId;
        }
    }
    $pass = new class  extends AbstractRecursivePass {
        public Reference $ref;
        public string $sourceId;
        public array $alternatives;
        public function processValue(mixed $value, bool $isRoot = false) : mixed {
            if ($this->ref !== $value) {
                return parent::processValue($value, $isRoot);
            }
            $sourceId = $this->sourceId;
            if (null !== $this->currentId && $this->currentId !== (string) $value) {
                $sourceId = $this->currentId . '" in the container provided to "' . $sourceId;
            }
            throw new ServiceNotFoundException((string) $value, $sourceId, null, $this->alternatives);
        }

};
    $pass->ref = $ref;
    $pass->sourceId = $sourceId;
    $pass->alternatives = $alternatives;
    $pass->processValue($value, true);
}
RSS feed
Powered by Drupal