44Service Subscribers & Locators
55==============================
66
7+ .. versionadded :: 3.3
8+ Service subscribers and locators were introduced in Symfony 3.3.
9+
710Sometimes, a service needs access to several other services without being sure
811that all of them will actually be used. In those cases, you may want the
912instantiation of the services to be lazy. However, that's not possible using
@@ -110,7 +113,7 @@ a PSR-11 ``ContainerInterface``::
110113 {
111114 return [
112115 'AppBundle\FooCommand' => FooHandler::class,
113- 'AppBundle\BarCommand' => BarHandler::class
116+ 'AppBundle\BarCommand' => BarHandler::class,
114117 ];
115118 }
116119
@@ -153,8 +156,8 @@ service locator::
153156 public static function getSubscribedServices()
154157 {
155158 return [
156- //...
157- LoggerInterface::class
159+ // ...
160+ LoggerInterface::class,
158161 ];
159162 }
160163
@@ -165,8 +168,8 @@ Service types can also be keyed by a service name for internal use::
165168 public static function getSubscribedServices()
166169 {
167170 return [
168- //...
169- 'logger' => LoggerInterface::class
171+ // ...
172+ 'logger' => LoggerInterface::class,
170173 ];
171174 }
172175
@@ -181,8 +184,8 @@ errors if there's no matching service found in the service container::
181184 public static function getSubscribedServices()
182185 {
183186 return [
184- //...
185- '?'.LoggerInterface::class
187+ // ...
188+ '?'.LoggerInterface::class,
186189 ];
187190 }
188191
@@ -231,7 +234,7 @@ service type to a service.
231234 // app/config/services.php
232235 use AppBundle\CommandBus;
233236
234- //...
237+ // ...
235238
236239 $container
237240 ->register(CommandBus::class)
@@ -291,7 +294,7 @@ include as many services as needed in it.
291294 use Symfony\Component\DependencyInjection\ServiceLocator;
292295 use Symfony\Component\DependencyInjection\Reference;
293296
294- //...
297+ // ...
295298
296299 $container
297300 ->register('app.command_handler_locator', ServiceLocator::class)
0 commit comments