function UpdateCompilerPass::process

Same name in other branches
  1. 9 core/lib/Drupal/Core/Update/UpdateCompilerPass.php \Drupal\Core\Update\UpdateCompilerPass::process()
  2. 8.9.x core/lib/Drupal/Core/Update/UpdateCompilerPass.php \Drupal\Core\Update\UpdateCompilerPass::process()
  3. 10 core/lib/Drupal/Core/Update/UpdateCompilerPass.php \Drupal\Core\Update\UpdateCompilerPass::process()

File

core/lib/Drupal/Core/Update/UpdateCompilerPass.php, line 21

Class

UpdateCompilerPass
Removes services with unmet dependencies.

Namespace

Drupal\Core\Update

Code

public function process(ContainerBuilder $container) {
    $process_aliases = FALSE;
    // Loop over the defined services and remove any with unmet dependencies.
    // The kernel cannot be booted if the container has such services. This
    // allows modules to run their update hooks to enable newly added
    // dependencies.
    do {
        $has_changed = FALSE;
        foreach ($container->getDefinitions() as $key => $definition) {
            // Ensure all the definition's arguments are valid.
            foreach ($definition->getArguments() as $argument) {
                if ($this->isArgumentMissingService($argument, $container)) {
                    $container->removeDefinition($key);
                    $container->log($this, sprintf('Removed service "%s"; reason: depends on non-existent service "%s".', $key, (string) $argument));
                    $has_changed = TRUE;
                    $process_aliases = TRUE;
                    // Process the next definition.
                    continue 2;
                }
            }
            // Ensure all the method call arguments are valid.
            foreach ($definition->getMethodCalls() as $call) {
                foreach ($call[1] as $argument) {
                    if ($this->isArgumentMissingService($argument, $container)) {
                        $container->removeDefinition($key);
                        $container->log($this, sprintf('Removed service "%s"; reason: method call "%s" depends on non-existent service "%s".', $key, $call[0], (string) $argument));
                        $has_changed = TRUE;
                        $process_aliases = TRUE;
                        // Process the next definition.
                        continue 3;
                    }
                }
            }
        }
        // Repeat if services have been removed.
    } while ($has_changed);
    // Remove aliases to services that have been removed. This does not need to
    // be part of the loop above because references to aliases have already been
    // resolved by Symfony's ResolveReferencesToAliasesPass.
    if ($process_aliases) {
        foreach ($container->getAliases() as $key => $alias) {
            $id = (string) $alias;
            if (!$container->has($id)) {
                $container->removeAlias($key);
                $container->log($this, sprintf('Removed alias "%s"; reason: alias to non-existent service "%s".', $key, $id));
            }
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.