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