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

Breadcrumb

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

class ResolveReferencesToAliasesPass

Replaces all references to aliases with references to the actual service.

@author Johannes M. Schmitt <schmittjoh@gmail.com>

Hierarchy

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

Expanded class hierarchy of ResolveReferencesToAliasesPass

File

vendor/symfony/dependency-injection/Compiler/ResolveReferencesToAliasesPass.php, line 23

Namespace

Symfony\Component\DependencyInjection\Compiler
View source
class ResolveReferencesToAliasesPass extends AbstractRecursivePass {
    protected bool $skipScalars = true;
    public function process(ContainerBuilder $container) : void {
        parent::process($container);
        foreach ($container->getAliases() as $id => $alias) {
            $aliasId = (string) $alias;
            $this->currentId = $id;
            if ($aliasId !== ($defId = $this->getDefinitionId($aliasId, $container))) {
                $container->setAlias($id, $defId)
                    ->setPublic($alias->isPublic());
            }
        }
    }
    protected function processValue(mixed $value, bool $isRoot = false) : mixed {
        if (!$value instanceof Reference) {
            return parent::processValue($value, $isRoot);
        }
        $defId = $this->getDefinitionId($id = (string) $value, $this->container);
        return $defId !== $id ? new Reference($defId, $value->getInvalidBehavior()) : $value;
    }
    private function getDefinitionId(string $id, ContainerBuilder $container) : string {
        if (!$container->hasAlias($id)) {
            return $id;
        }
        $alias = $container->getAlias($id);
        if ($alias->isDeprecated()) {
            $referencingDefinition = $container->hasDefinition($this->currentId) ? $container->getDefinition($this->currentId) : $container->getAlias($this->currentId);
            if (!$referencingDefinition->isDeprecated()) {
                $deprecation = $alias->getDeprecation($id);
                trigger_deprecation($deprecation['package'], $deprecation['version'], rtrim($deprecation['message'], '. ') . '. It is being referenced by the "%s" ' . ($container->hasDefinition($this->currentId) ? 'service.' : 'alias.'), $this->currentId);
            }
        }
        $seen = [];
        do {
            if (isset($seen[$id])) {
                throw new ServiceCircularReferenceException($id, array_merge(array_keys($seen), [
                    $id,
                ]));
            }
            $seen[$id] = true;
            $id = (string) $container->getAlias($id);
        } while ($container->hasAlias($id));
        return $id;
    }

}

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
ResolveReferencesToAliasesPass::$skipScalars protected property Overrides AbstractRecursivePass::$skipScalars
ResolveReferencesToAliasesPass::getDefinitionId private function
ResolveReferencesToAliasesPass::process public function You can modify the container here before it is dumped to PHP code. Overrides AbstractRecursivePass::process
ResolveReferencesToAliasesPass::processValue protected function Processes a value found in a definition tree. Overrides AbstractRecursivePass::processValue
RSS feed
Powered by Drupal