3 namespace Drupal\Core\Installer;
5 use Drupal\Core\DependencyInjection\ContainerBuilder;
6 use Drupal\Core\DependencyInjection\ServiceProviderInterface;
7 use Drupal\Core\DependencyInjection\ServiceModifierInterface;
8 use Symfony\Component\DependencyInjection\Reference;
11 * Service provider for the early installer environment.
13 * This class is manually added by install_begin_request() via
14 * $conf['container_service_providers'] and required to prevent various services
15 * from trying to retrieve data from storages that do not exist yet.
17 class InstallerServiceProvider implements ServiceProviderInterface, ServiceModifierInterface {
22 public function register(ContainerBuilder $container) {
23 // Inject the special configuration storage for the installer.
24 // This special implementation MUST NOT be used anywhere else than the early
25 // installer environment.
26 $container->register('config.storage', 'Drupal\Core\Config\InstallStorage');
28 // Replace services with in-memory implementations.
29 $definition = $container->getDefinition('cache_factory');
30 $definition->setClass('Drupal\Core\Cache\MemoryBackendFactory');
31 $definition->setArguments([]);
32 $definition->setMethodCalls([]);
34 ->register('keyvalue', 'Drupal\Core\KeyValueStore\KeyValueMemoryFactory');
36 ->register('keyvalue.expirable', 'Drupal\Core\KeyValueStore\KeyValueNullExpirableFactory');
38 // Replace services with no-op implementations.
40 ->register('lock', 'Drupal\Core\Lock\NullLockBackend');
42 ->register('url_generator', 'Drupal\Core\Routing\NullGenerator')
43 ->addArgument(new Reference('request_stack'));
45 ->register('path_processor_manager', 'Drupal\Core\PathProcessor\NullPathProcessorManager');
47 ->register('router.dumper', 'Drupal\Core\Routing\NullMatcherDumper');
49 // Remove the cache tags invalidator tag from the cache tags storage, so
50 // that we don't call it when cache tags are invalidated very early in the
52 $container->getDefinition('cache_tags.invalidator.checksum')
53 ->clearTag('cache_tags_invalidator');
55 // Replace the route builder with an empty implementation.
56 // @todo Convert installer steps into routes; add an installer.routing.yml.
57 $definition = $container->getDefinition('router.builder');
58 $definition->setClass('Drupal\Core\Installer\InstallerRouteBuilder')
59 // The core router builder, but there is no reason here to be lazy, so
60 // we don't need to ship with a custom proxy class.
63 // Use a performance optimised module extension list.
64 $container->getDefinition('extension.list.module')->setClass('Drupal\Core\Installer\InstallerModuleExtensionList');
70 public function alter(ContainerBuilder $container) {
71 // Disable Twig cache (php storage does not exist yet).
72 $twig_config = $container->getParameter('twig.config');
73 $twig_config['cache'] = FALSE;
74 $container->setParameter('twig.config', $twig_config);
76 // No service may persist when the early installer kernel is rebooted into
77 // the production environment.
78 // @todo The DrupalKernel reboot performed by drupal_install_system() is
79 // actually not a "regular" reboot (like ModuleInstaller::install()), so
80 // services are not actually persisted.
81 foreach ($container->findTaggedServiceIds('persist') as $id => $tags) {
82 $definition = $container->getDefinition($id);
83 $definition->clearTag('persist');