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

Breadcrumb

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

class DefinitionErrorExceptionPass

Throws an exception for any Definitions that have errors and still exist.

@author Ryan Weaver <ryan@knpuniversity.com>

Hierarchy

  • class \Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass implements \Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface
    • class \Symfony\Component\DependencyInjection\Compiler\DefinitionErrorExceptionPass extends \Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass

Expanded class hierarchy of DefinitionErrorExceptionPass

File

vendor/symfony/dependency-injection/Compiler/DefinitionErrorExceptionPass.php, line 26

Namespace

Symfony\Component\DependencyInjection\Compiler
View source
class DefinitionErrorExceptionPass extends AbstractRecursivePass {
    protected bool $skipScalars = true;
    private array $erroredDefinitions = [];
    private array $sourceReferences = [];
    public function process(ContainerBuilder $container) : void {
        try {
            parent::process($container);
            $visitedIds = [];
            foreach ($this->erroredDefinitions as $id => $definition) {
                if ($this->isErrorForRuntime($id, $visitedIds)) {
                    continue;
                }
                // only show the first error so the user can focus on it
                $errors = $definition->getErrors();
                throw new RuntimeException(reset($errors));
            }
        } finally {
            $this->erroredDefinitions = [];
            $this->sourceReferences = [];
        }
    }
    protected function processValue(mixed $value, bool $isRoot = false) : mixed {
        if ($value instanceof ArgumentInterface) {
            parent::processValue($value->getValues());
            return $value;
        }
        if ($value instanceof Reference && $this->currentId !== ($targetId = (string) $value)) {
            if (ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE === $value->getInvalidBehavior()) {
                $this->sourceReferences[$targetId][$this->currentId] ??= true;
            }
            else {
                $this->sourceReferences[$targetId][$this->currentId] = false;
            }
            return $value;
        }
        if (!$value instanceof Definition || !$value->hasErrors() || $value->hasTag('container.error')) {
            return parent::processValue($value, $isRoot);
        }
        $this->erroredDefinitions[$this->currentId] = $value;
        return parent::processValue($value);
    }
    private function isErrorForRuntime(string $id, array &$visitedIds) : bool {
        if (!isset($this->sourceReferences[$id])) {
            return false;
        }
        if (isset($visitedIds[$id])) {
            return $visitedIds[$id];
        }
        $visitedIds[$id] = true;
        foreach ($this->sourceReferences[$id] as $sourceId => $isRuntime) {
            if ($visitedIds[$sourceId] ?? ($visitedIds[$sourceId] = $this->isErrorForRuntime($sourceId, $visitedIds))) {
                continue;
            }
            if (!$isRuntime) {
                return false;
            }
        }
        return true;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
AbstractRecursivePass::$container protected property
AbstractRecursivePass::$currentId protected property
AbstractRecursivePass::$expressionLanguage private property 1
AbstractRecursivePass::$inExpression private property
AbstractRecursivePass::$processExpressions private property
AbstractRecursivePass::enableExpressionProcessing protected function
AbstractRecursivePass::getConstructor protected function
AbstractRecursivePass::getExpressionLanguage private function 1
AbstractRecursivePass::getReflectionMethod protected function
AbstractRecursivePass::inExpression protected function
DefinitionErrorExceptionPass::$erroredDefinitions private property
DefinitionErrorExceptionPass::$skipScalars protected property Overrides AbstractRecursivePass::$skipScalars
DefinitionErrorExceptionPass::$sourceReferences private property
DefinitionErrorExceptionPass::isErrorForRuntime private function
DefinitionErrorExceptionPass::process public function You can modify the container here before it is dumped to PHP code. Overrides AbstractRecursivePass::process
DefinitionErrorExceptionPass::processValue protected function Processes a value found in a definition tree. Overrides AbstractRecursivePass::processValue
RSS feed
Powered by Drupal