Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Neirda24 wants to merge4 commits intosymfony:7.2
base:7.2
Choose a base branch
Loading
fromNeirda24:update-service-subscriber
Open
Changes fromall commits
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
12 changes: 12 additions & 0 deletionsservice_container/service_subscribers_locators.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -140,6 +140,18 @@ count and iterate over the services of the locator::
The :class:`Symfony\\Contracts\\Service\\ServiceCollectionInterface` was
introduced in Symfony 7.1.

Without autowire

Choose a reason for hiding this comment

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

maybe this?

Suggested change
Without autowire
Manually wiring a locator

Choose a reason for hiding this comment

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

or a.. note:: indeed as suggested by Oskar

Copy link
Author

Choose a reason for hiding this comment

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

is it possible to add code block in a note ?

~~~~~~~~~~~~~~~~

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)``.

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 usingautowire you need torequire either``Psr\Container\ContainerInterface``or ``Symfony\Contracts\Service\ServiceProviderInterface`` as a ``__construct`` argument oras amethod call like ``setContainer(Psr\Container\ContainerInterface $container)``.
If you are not usingautowiring, you need toreference the special``Psr\Container\ContainerInterface``service where the locator should be inject (typicallyas aconstructor argument.)


.. code-block:: diff

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

[8]ページ先頭

©2009-2025 Movatter.jp