InstallerServiceProvider.php 3.6 KB

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