4
4
Service Subscribers & Locators
5
5
==============================
6
6
7
+ .. versionadded :: 3.3
8
+ Service subscribers and locators were introduced in Symfony 3.3.
9
+
7
10
Sometimes, a service needs access to several other services without being sure
8
11
that all of them will actually be used. In those cases, you may want the
9
12
instantiation of the services to be lazy. However, that's not possible using
@@ -110,7 +113,7 @@ a PSR-11 ``ContainerInterface``::
110
113
{
111
114
return [
112
115
'AppBundle\FooCommand' => FooHandler::class,
113
- 'AppBundle\BarCommand' => BarHandler::class
116
+ 'AppBundle\BarCommand' => BarHandler::class,
114
117
];
115
118
}
116
119
@@ -153,8 +156,8 @@ service locator::
153
156
public static function getSubscribedServices()
154
157
{
155
158
return [
156
- //...
157
- LoggerInterface::class
159
+ // ...
160
+ LoggerInterface::class,
158
161
];
159
162
}
160
163
@@ -165,8 +168,8 @@ Service types can also be keyed by a service name for internal use::
165
168
public static function getSubscribedServices()
166
169
{
167
170
return [
168
- //...
169
- 'logger' => LoggerInterface::class
171
+ // ...
172
+ 'logger' => LoggerInterface::class,
170
173
];
171
174
}
172
175
@@ -181,8 +184,8 @@ errors if there's no matching service found in the service container::
181
184
public static function getSubscribedServices()
182
185
{
183
186
return [
184
- //...
185
- '?'.LoggerInterface::class
187
+ // ...
188
+ '?'.LoggerInterface::class,
186
189
];
187
190
}
188
191
@@ -231,7 +234,7 @@ service type to a service.
231
234
// app/config/services.php
232
235
use AppBundle\CommandBus;
233
236
234
- //...
237
+ // ...
235
238
236
239
$container
237
240
->register(CommandBus::class)
@@ -291,7 +294,7 @@ include as many services as needed in it.
291
294
use Symfony\Component\DependencyInjection\ServiceLocator;
292
295
use Symfony\Component\DependencyInjection\Reference;
293
296
294
- //...
297
+ // ...
295
298
296
299
$container
297
300
->register('app.command_handler_locator', ServiceLocator::class)
0 commit comments