Patched to Drupal 8.4.8 level. See https://www.drupal.org/sa-core-2018-004 and patch...
[yaffs-website] / web / core / lib / Drupal / Core / Installer / InstallerServiceProvider.php
1 <?php
2
3 namespace Drupal\Core\Installer;
4
5 use Drupal\Core\DependencyInjection\ContainerBuilder;
6 use Drupal\Core\DependencyInjection\ServiceProviderInterface;
7 use Drupal\Core\DependencyInjection\ServiceModifierInterface;
8 use Symfony\Component\DependencyInjection\Reference;
9
10 /**
11  * Service provider for the early installer environment.
12  *
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.
16  */
17 class InstallerServiceProvider implements ServiceProviderInterface, ServiceModifierInterface {
18
19   /**
20    * {@inheritdoc}
21    */
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');
27
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([]);
33     $container
34       ->register('keyvalue', 'Drupal\Core\KeyValueStore\KeyValueMemoryFactory');
35     $container
36       ->register('keyvalue.expirable', 'Drupal\Core\KeyValueStore\KeyValueNullExpirableFactory');
37
38     // Replace services with no-op implementations.
39     $container
40       ->register('lock', 'Drupal\Core\Lock\NullLockBackend');
41     $container
42       ->register('url_generator', 'Drupal\Core\Routing\NullGenerator')
43       ->addArgument(new Reference('request_stack'));
44     $container
45       ->register('path_processor_manager', 'Drupal\Core\PathProcessor\NullPathProcessorManager');
46     $container
47       ->register('router.dumper', 'Drupal\Core\Routing\NullMatcherDumper');
48
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
51     // installer.
52     $container->getDefinition('cache_tags.invalidator.checksum')
53       ->clearTag('cache_tags_invalidator');
54
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.
61       ->setLazy(FALSE);
62   }
63
64   /**
65    * {@inheritdoc}
66    */
67   public function alter(ContainerBuilder $container) {
68     // Disable Twig cache (php storage does not exist yet).
69     $twig_config = $container->getParameter('twig.config');
70     $twig_config['cache'] = FALSE;
71     $container->setParameter('twig.config', $twig_config);
72
73     // No service may persist when the early installer kernel is rebooted into
74     // the production environment.
75     // @todo The DrupalKernel reboot performed by drupal_install_system() is
76     //   actually not a "regular" reboot (like ModuleInstaller::install()), so
77     //   services are not actually persisted.
78     foreach ($container->findTaggedServiceIds('persist') as $id => $tags) {
79       $definition = $container->getDefinition($id);
80       $definition->clearTag('persist');
81     }
82   }
83
84 }