Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[DI] Service subscribers #9223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 18, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Incorporate feedback
  • Loading branch information
codedmonkey committed Apr 18, 2018
commit b1f0343ad2e7f8a456fefb87f206daa40a87a671
2 changes: 1 addition & 1 deletion 2 service_container/lazy_services.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Lazy Services

.. seealso::

Another way to inject services lazily is via a :doc:`service subscriber </service_container/service_subscribers>`.
Another way to inject services lazily is via a :doc:`service subscriber </service_container/service_subscribers_locators>`.

Why Lazy Services?
------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.. index::
single: DependencyInjection; Service Subscribers

Service Subscribers
===================
Service Subscribers & Locators
==============================

Sometimes, a service needs access to several other services without being sure
that all of them will actually be used. In those cases, you may want the
Expand Down Expand Up @@ -85,7 +85,7 @@ Defining a Service Subscriber
-----------------------------

First, turn ``CommandBus`` into an implementation of :class:`Symfony\\Component\\DependencyInjection\\ServiceSubscriberInterface`.
Use its ``getSubscribedServices`` method to include as many services as needed
Use its ``getSubscribedServices()`` method to include as many services as needed
in the service subscriber and change the type hint of the container to
a PSR-11 ``ContainerInterface``::

Expand Down Expand Up @@ -141,7 +141,7 @@ which implements the PSR-11 ``ContainerInterface``, but it is also a callable::

return $handler->handle($command);

Including services
Including Services
------------------

In order to add a new dependency to the service subscriber, use the
Expand All @@ -158,7 +158,7 @@ service locator::
];
}

Service types can also be keyed by a service name for use internally::
Service types can also be keyed by a service name for internal use::

use Psr\Log\LoggerInterface;

Expand All @@ -170,7 +170,7 @@ Service types can also be keyed by a service name for use internally::
];
}

Optional services
Optional Services
~~~~~~~~~~~~~~~~~

For optional dependencies, prepend the service type with a ``?`` to prevent
Expand All @@ -191,7 +191,7 @@ errors if there's no matching service found in the service container::
Make sure an optional service exists by calling ``has()`` on the service
locator before calling the service itself.

Aliased services
Aliased Services
~~~~~~~~~~~~~~~~

By default, autowiring is used to match a service type to a service from the
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.