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

[DependencyInjection] Add exclude to TaggedIterator and TaggedLocator#17645

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

Merged
Merged
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
70 changes: 70 additions & 0 deletionsservice_container/tags.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -591,6 +591,76 @@ application handlers::
}
}

If for some reason you need to exclude one or multiple services when using a tagged
iterator, this can be done by using the ``exclude`` option:

.. configuration-block::

.. code-block:: yaml

# config/services.yaml
services:
# ...

# This is the service we want to exclude, even if the 'app.handler' tag is attached
App\Handler\Three:
tags: ['app.handler']

App\HandlerCollection:
arguments:
- !tagged_iterator { tag: app.handler, exclude: ['App\Handler\Three'] }

.. code-block:: xml

<!-- config/services.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<!-- ... -->

<!-- This is the service we want to exclude, even if the 'app.handler' tag is attached -->
<service id="App\Handler\Three">
<tag name="app.handler"/>
</service>

<service id="App\HandlerCollection">
<!-- inject all services tagged with app.handler as first argument -->
<argument type="tagged_iterator" tag="app.handler">
<exclude>App\Handler\Three</exclude>
</argument>
</service>
</services>
</container>

.. code-block:: php

// config/services.php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

return function(ContainerConfigurator $configurator) {
$services = $configurator->services();

// ...

// This is the service we want to exclude, even if the 'app.handler' tag is attached
$services->set(App\Handler\Three::class)
->tag('app.handler')
;

$services->set(App\HandlerCollection::class)
// inject all services tagged with app.handler as first argument
->args([tagged_iterator('app.handler', exclude: [App\Handler\Three::class])])
;
};

.. versionadded:: 6.1
Copy link
Contributor

@dbrumanndbrumannJan 4, 2023
edited
Loading

Choose a reason for hiding this comment

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

Is this right?symfony/symfony#47902 was merged into the 6.2 branch.

Nevermind, I just saw that the initial implementation was done in 6.1.

javiereguiluz reacted with thumbs up emoji

The ``exclude`` option was introduced in Symfony 6.1.

.. seealso::

See also :doc:`tagged locator services </service_container/service_subscribers_locators>`
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp