comparison core/lib/Drupal/Core/CoreServiceProvider.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 1fec387a4317
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\Core;
4
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;
32
33 /**
34 * ServiceProvider class for mandatory core services.
35 *
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).
39 *
40 * Modules wishing to register services to the container should use
41 * modulename.services.yml in their respective directories.
42 *
43 * @ingroup container
44 */
45 class CoreServiceProvider implements ServiceProviderInterface, ServiceModifierInterface {
46
47 /**
48 * {@inheritdoc}
49 */
50 public function register(ContainerBuilder $container) {
51 $this->registerTest($container);
52
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']);
57 }
58
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());
63
64 $container->addCompilerPass(new ProxyServicesPass());
65
66 $container->addCompilerPass(new BackendCompilerPass());
67
68 $container->addCompilerPass(new CorsCompilerPass());
69
70 $container->addCompilerPass(new StackedKernelPass());
71
72 $container->addCompilerPass(new StackedSessionHandlerPass());
73
74 $container->addCompilerPass(new MainContentRenderersPass());
75
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());
80
81 $container->addCompilerPass(new TwigExtensionPass());
82
83 // Add a compiler pass for registering event subscribers.
84 $container->addCompilerPass(new RegisterEventSubscribersPass(), PassConfig::TYPE_AFTER_REMOVING);
85
86 $container->addCompilerPass(new RegisterAccessChecksPass());
87 $container->addCompilerPass(new RegisterLazyRouteEnhancers());
88 $container->addCompilerPass(new RegisterLazyRouteFilters());
89
90 // Add a compiler pass for registering services needing destruction.
91 $container->addCompilerPass(new RegisterServicesForDestructionPass());
92
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());
98
99 // Register plugin managers.
100 $container->addCompilerPass(new PluginManagerPass());
101
102 $container->addCompilerPass(new DependencySerializationTraitPass());
103 }
104
105 /**
106 * Alters the UUID service to use the most efficient method available.
107 *
108 * @param \Drupal\Core\DependencyInjection\ContainerBuilder $container
109 * The container builder.
110 */
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
115 // PECL functions.
116 if (function_exists('uuid_create') && !function_exists('uuid_make')) {
117 $uuid_service->setClass('Drupal\Component\Uuid\Pecl');
118 }
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');
122 }
123 }
124
125 /**
126 * Registers services and event subscribers for a site under test.
127 *
128 * @param \Drupal\Core\DependencyInjection\ContainerBuilder $container
129 * The container builder.
130 */
131 protected function registerTest(ContainerBuilder $container) {
132 // Do nothing if we are not in a test environment.
133 if (!drupal_valid_test_ua()) {
134 return;
135 }
136 // Add the HTTP request middleware to Guzzle.
137 $container
138 ->register('test.http_client.middleware', 'Drupal\Core\Test\HttpClientMiddleware\TestHttpClientMiddleware')
139 ->addTag('http_client_middleware');
140 }
141
142 }