1
1
.. index ::
2
2
single: DependencyInjection; Service Subscribers
3
3
4
- Service Subscribers
5
- ===================
4
+ Service Subscribers & Locators
5
+ ==============================
6
6
7
7
Sometimes, a service needs access to several other services without being sure
8
8
that all of them will actually be used. In those cases, you may want the
@@ -85,7 +85,7 @@ Defining a Service Subscriber
85
85
-----------------------------
86
86
87
87
First, turn ``CommandBus `` into an implementation of :class: `Symfony\\ Component\\ DependencyInjection\\ ServiceSubscriberInterface `.
88
- Use its ``getSubscribedServices `` method to include as many services as needed
88
+ Use its ``getSubscribedServices() `` method to include as many services as needed
89
89
in the service subscriber and change the type hint of the container to
90
90
a PSR-11 ``ContainerInterface ``::
91
91
@@ -141,7 +141,7 @@ which implements the PSR-11 ``ContainerInterface``, but it is also a callable::
141
141
142
142
return $handler->handle($command);
143
143
144
- Including services
144
+ Including Services
145
145
------------------
146
146
147
147
In order to add a new dependency to the service subscriber, use the
@@ -158,7 +158,7 @@ service locator::
158
158
];
159
159
}
160
160
161
- Service types can also be keyed by a service name for use internally ::
161
+ Service types can also be keyed by a service name for internal use ::
162
162
163
163
use Psr\Log\LoggerInterface;
164
164
@@ -170,7 +170,7 @@ Service types can also be keyed by a service name for use internally::
170
170
];
171
171
}
172
172
173
- Optional services
173
+ Optional Services
174
174
~~~~~~~~~~~~~~~~~
175
175
176
176
For optional dependencies, prepend the service type with a ``? `` to prevent
@@ -191,7 +191,7 @@ errors if there's no matching service found in the service container::
191
191
Make sure an optional service exists by calling ``has() `` on the service
192
192
locator before calling the service itself.
193
193
194
- Aliased services
194
+ Aliased Services
195
195
~~~~~~~~~~~~~~~~
196
196
197
197
By default, autowiring is used to match a service type to a service from the
0 commit comments