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\DependencySerializationTraitPass;
14 use Drupal\Core\DependencyInjection\Compiler\StackedKernelPass;
15 use Drupal\Core\DependencyInjection\Compiler\StackedSessionHandlerPass;
16 use Drupal\Core\DependencyInjection\Compiler\RegisterStreamWrappersPass;
17 use Drupal\Core\DependencyInjection\Compiler\TwigExtensionPass;
18 use Drupal\Core\DependencyInjection\ServiceModifierInterface;
19 use Drupal\Core\DependencyInjection\ServiceProviderInterface;
20 use Drupal\Core\DependencyInjection\ContainerBuilder;
21 use Drupal\Core\DependencyInjection\Compiler\ModifyServiceDefinitionsPass;
22 use Drupal\Core\DependencyInjection\Compiler\TaggedHandlersPass;
23 use Drupal\Core\DependencyInjection\Compiler\RegisterEventSubscribersPass;
24 use Drupal\Core\DependencyInjection\Compiler\RegisterAccessChecksPass;
25 use Drupal\Core\DependencyInjection\Compiler\RegisterServicesForDestructionPass;
26 use Drupal\Core\Plugin\PluginManagerPass;
27 use Drupal\Core\Render\MainContent\MainContentRenderersPass;
28 use Drupal\Core\Site\Settings;
29 use Symfony\Component\DependencyInjection\Compiler\PassConfig;
32 * ServiceProvider class for mandatory core services.
34 * This is where Drupal core registers all of its compiler passes.
35 * The service definitions themselves are in core/core.services.yml with a
36 * few, documented exceptions (typically, install requirements).
38 * Modules wishing to register services to the container should use
39 * modulename.services.yml in their respective directories.
43 class CoreServiceProvider implements ServiceProviderInterface, ServiceModifierInterface {
48 public function register(ContainerBuilder $container) {
49 $this->registerTest($container);
51 // Only register the private file stream wrapper if a file path has been set.
52 if (Settings::get('file_private_path')) {
53 $container->register('stream_wrapper.private', 'Drupal\Core\StreamWrapper\PrivateStream')
54 ->addTag('stream_wrapper', ['scheme' => 'private']);
57 // Add the compiler pass that lets service providers modify existing
58 // service definitions. This pass must come first so that later
59 // list-building passes are operating on the post-alter services list.
60 $container->addCompilerPass(new ModifyServiceDefinitionsPass());
62 $container->addCompilerPass(new ProxyServicesPass());
64 $container->addCompilerPass(new BackendCompilerPass());
66 $container->addCompilerPass(new CorsCompilerPass());
68 $container->addCompilerPass(new StackedKernelPass());
70 $container->addCompilerPass(new StackedSessionHandlerPass());
72 $container->addCompilerPass(new MainContentRenderersPass());
74 // Collect tagged handler services as method calls on consumer services.
75 $container->addCompilerPass(new TaggedHandlersPass());
76 $container->addCompilerPass(new RegisterStreamWrappersPass());
77 $container->addCompilerPass(new GuzzleMiddlewarePass());
79 $container->addCompilerPass(new TwigExtensionPass());
81 // Add a compiler pass for registering event subscribers.
82 $container->addCompilerPass(new RegisterEventSubscribersPass(), PassConfig::TYPE_AFTER_REMOVING);
84 $container->addCompilerPass(new RegisterAccessChecksPass());
86 // Add a compiler pass for registering services needing destruction.
87 $container->addCompilerPass(new RegisterServicesForDestructionPass());
89 // Add the compiler pass that will process the tagged services.
90 $container->addCompilerPass(new ListCacheBinsPass());
91 $container->addCompilerPass(new CacheContextsPass());
92 $container->addCompilerPass(new ContextProvidersPass());
93 $container->addCompilerPass(new AuthenticationProviderPass());
95 // Register plugin managers.
96 $container->addCompilerPass(new PluginManagerPass());
98 $container->addCompilerPass(new DependencySerializationTraitPass());
102 * Alters the UUID service to use the most efficient method available.
104 * @param \Drupal\Core\DependencyInjection\ContainerBuilder $container
105 * The container builder.
107 public function alter(ContainerBuilder $container) {
108 $uuid_service = $container->getDefinition('uuid');
109 // Debian/Ubuntu uses the (broken) OSSP extension as their UUID
110 // implementation. The OSSP implementation is not compatible with the
112 if (function_exists('uuid_create') && !function_exists('uuid_make')) {
113 $uuid_service->setClass('Drupal\Component\Uuid\Pecl');
115 // Try to use the COM implementation for Windows users.
116 elseif (function_exists('com_create_guid')) {
117 $uuid_service->setClass('Drupal\Component\Uuid\Com');
122 * Registers services and event subscribers for a site under test.
124 * @param \Drupal\Core\DependencyInjection\ContainerBuilder $container
125 * The container builder.
127 protected function registerTest(ContainerBuilder $container) {
128 // Do nothing if we are not in a test environment.
129 if (!drupal_valid_test_ua()) {
132 // Add the HTTP request middleware to Guzzle.
134 ->register('test.http_client.middleware', 'Drupal\Core\Test\HttpClientMiddleware\TestHttpClientMiddleware')
135 ->addTag('http_client_middleware');