5 use Drupal\Core\Cache\Context\CacheContextsPass;
6 use Drupal\Core\Cache\ListCacheBinsPass;
7 use Drupal\Core\DependencyInjection\Compiler\AuthenticationProviderPass;
8 use Drupal\Core\DependencyInjection\Compiler\BackendCompilerPass;
9 use Drupal\Core\DependencyInjection\Compiler\CorsCompilerPass;
10 use Drupal\Core\DependencyInjection\Compiler\GuzzleMiddlewarePass;
11 use Drupal\Core\DependencyInjection\Compiler\ContextProvidersPass;
12 use Drupal\Core\DependencyInjection\Compiler\ProxyServicesPass;
13 use Drupal\Core\DependencyInjection\Compiler\RegisterLazyRouteEnhancers;
14 use Drupal\Core\DependencyInjection\Compiler\RegisterLazyRouteFilters;
15 use Drupal\Core\DependencyInjection\Compiler\DependencySerializationTraitPass;
16 use Drupal\Core\DependencyInjection\Compiler\StackedKernelPass;
17 use Drupal\Core\DependencyInjection\Compiler\StackedSessionHandlerPass;
18 use Drupal\Core\DependencyInjection\Compiler\RegisterStreamWrappersPass;
19 use Drupal\Core\DependencyInjection\Compiler\TwigExtensionPass;
20 use Drupal\Core\DependencyInjection\ServiceModifierInterface;
21 use Drupal\Core\DependencyInjection\ServiceProviderInterface;
22 use Drupal\Core\DependencyInjection\ContainerBuilder;
23 use Drupal\Core\DependencyInjection\Compiler\ModifyServiceDefinitionsPass;
24 use Drupal\Core\DependencyInjection\Compiler\TaggedHandlersPass;
25 use Drupal\Core\DependencyInjection\Compiler\RegisterEventSubscribersPass;
26 use Drupal\Core\DependencyInjection\Compiler\RegisterAccessChecksPass;
27 use Drupal\Core\DependencyInjection\Compiler\RegisterServicesForDestructionPass;
28 use Drupal\Core\Plugin\PluginManagerPass;
29 use Drupal\Core\Render\MainContent\MainContentRenderersPass;
30 use Drupal\Core\Site\Settings;
31 use Symfony\Component\DependencyInjection\Compiler\PassConfig;
34 * ServiceProvider class for mandatory core services.
36 * This is where Drupal core registers all of its compiler passes.
37 * The service definitions themselves are in core/core.services.yml with a
38 * few, documented exceptions (typically, install requirements).
40 * Modules wishing to register services to the container should use
41 * modulename.services.yml in their respective directories.
45 class CoreServiceProvider implements ServiceProviderInterface, ServiceModifierInterface {
50 public function register(ContainerBuilder $container) {
51 $this->registerTest($container);
53 // Only register the private file stream wrapper if a file path has been set.
54 if (Settings::get('file_private_path')) {
55 $container->register('stream_wrapper.private', 'Drupal\Core\StreamWrapper\PrivateStream')
56 ->addTag('stream_wrapper', ['scheme' => 'private']);
59 // Add the compiler pass that lets service providers modify existing
60 // service definitions. This pass must come first so that later
61 // list-building passes are operating on the post-alter services list.
62 $container->addCompilerPass(new ModifyServiceDefinitionsPass());
64 $container->addCompilerPass(new ProxyServicesPass());
66 $container->addCompilerPass(new BackendCompilerPass());
68 $container->addCompilerPass(new CorsCompilerPass());
70 $container->addCompilerPass(new StackedKernelPass());
72 $container->addCompilerPass(new StackedSessionHandlerPass());
74 $container->addCompilerPass(new MainContentRenderersPass());
76 // Collect tagged handler services as method calls on consumer services.
77 $container->addCompilerPass(new TaggedHandlersPass());
78 $container->addCompilerPass(new RegisterStreamWrappersPass());
79 $container->addCompilerPass(new GuzzleMiddlewarePass());
81 $container->addCompilerPass(new TwigExtensionPass());
83 // Add a compiler pass for registering event subscribers.
84 $container->addCompilerPass(new RegisterEventSubscribersPass(), PassConfig::TYPE_AFTER_REMOVING);
86 $container->addCompilerPass(new RegisterAccessChecksPass());
87 $container->addCompilerPass(new RegisterLazyRouteEnhancers());
88 $container->addCompilerPass(new RegisterLazyRouteFilters());
90 // Add a compiler pass for registering services needing destruction.
91 $container->addCompilerPass(new RegisterServicesForDestructionPass());
93 // Add the compiler pass that will process the tagged services.
94 $container->addCompilerPass(new ListCacheBinsPass());
95 $container->addCompilerPass(new CacheContextsPass());
96 $container->addCompilerPass(new ContextProvidersPass());
97 $container->addCompilerPass(new AuthenticationProviderPass());
99 // Register plugin managers.
100 $container->addCompilerPass(new PluginManagerPass());
102 $container->addCompilerPass(new DependencySerializationTraitPass());
106 * Alters the UUID service to use the most efficient method available.
108 * @param \Drupal\Core\DependencyInjection\ContainerBuilder $container
109 * The container builder.
111 public function alter(ContainerBuilder $container) {
112 $uuid_service = $container->getDefinition('uuid');
113 // Debian/Ubuntu uses the (broken) OSSP extension as their UUID
114 // implementation. The OSSP implementation is not compatible with the
116 if (function_exists('uuid_create') && !function_exists('uuid_make')) {
117 $uuid_service->setClass('Drupal\Component\Uuid\Pecl');
119 // Try to use the COM implementation for Windows users.
120 elseif (function_exists('com_create_guid')) {
121 $uuid_service->setClass('Drupal\Component\Uuid\Com');
126 * Registers services and event subscribers for a site under test.
128 * @param \Drupal\Core\DependencyInjection\ContainerBuilder $container
129 * The container builder.
131 protected function registerTest(ContainerBuilder $container) {
132 // Do nothing if we are not in a test environment.
133 if (!drupal_valid_test_ua()) {
136 // Add the HTTP request middleware to Guzzle.
138 ->register('test.http_client.middleware', 'Drupal\Core\Test\HttpClientMiddleware\TestHttpClientMiddleware')
139 ->addTag('http_client_middleware');