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