Skip to content

Add note about not using autowire with ServiceSubscriber #20961

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

Open
wants to merge 4 commits into
base: 7.2
Choose a base branch
from
Open
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
Next Next commit
Add example
  • Loading branch information
Neirda24 committed May 15, 2025
commit b4af396fecd4de36612cd9b04c4aa3292b4b3eee
6 changes: 6 additions & 0 deletions service_container/service_subscribers_locators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@

If you are not using autowire you need to require either ``Psr\Container\ContainerInterface`` or ``Symfony\Contracts\Service\ServiceProviderInterface`` as a ``__construct`` argument or as a method call like ``setContainer(Psr\Container\ContainerInterface $container)``.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If you are not using autowire you need to require either ``Psr\Container\ContainerInterface`` or ``Symfony\Contracts\Service\ServiceProviderInterface`` as a ``__construct`` argument or as a method call like ``setContainer(Psr\Container\ContainerInterface $container)``.
If you are not using autowiring, you need to reference the special ``Psr\Container\ContainerInterface`` service where the locator should be inject (typically as a constructor argument.)


.. code-block:: diff

Check failure on line 148 in service_container/service_subscribers_locators.rst

View workflow job for this annotation

GitHub Actions / Lint (DOCtor-RST)

Please add a blank line after ".. code-block:: diff
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess a .. configuration-block:: would be preferable, since this diff applies to nothing currently?

$services->set('my_service', SomeClass::class)
+ ->call('setContainer', [service(ContainerInterface::class)])
+ ->tag('container.service_subscriber')
;

Including Services
------------------

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy