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

Commit27d591d

Browse files
committed
minor#17645 [DependencyInjection] Add exclude to TaggedIterator and TaggedLocator (alexandre-daubois)
This PR was merged into the 6.1 branch.Discussion----------[DependencyInjection] Add exclude to TaggedIterator and TaggedLocatorResolves#16339Commits-------aac1e7d [DependencyInjection] Add exclude to TaggedIterator and TaggedLocator
2 parents623d478 +aac1e7d commit27d591d

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

‎service_container/tags.rst‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,76 @@ application handlers::
591591
}
592592
}
593593

594+
If for some reason you need to exclude one or multiple services when using a tagged
595+
iterator, this can be done by using the ``exclude`` option:
596+
597+
..configuration-block::
598+
599+
..code-block::yaml
600+
601+
# config/services.yaml
602+
services:
603+
# ...
604+
605+
# This is the service we want to exclude, even if the 'app.handler' tag is attached
606+
App\Handler\Three:
607+
tags:['app.handler']
608+
609+
App\HandlerCollection:
610+
arguments:
611+
-!tagged_iterator{ tag: app.handler, exclude: ['App\Handler\Three'] }
612+
613+
..code-block::xml
614+
615+
<!-- config/services.xml-->
616+
<?xml version="1.0" encoding="UTF-8" ?>
617+
<containerxmlns="http://symfony.com/schema/dic/services"
618+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
619+
xsi:schemaLocation="http://symfony.com/schema/dic/services
620+
https://symfony.com/schema/dic/services/services-1.0.xsd">
621+
622+
<services>
623+
<!-- ...-->
624+
625+
<!-- This is the service we want to exclude, even if the 'app.handler' tag is attached-->
626+
<serviceid="App\Handler\Three">
627+
<tagname="app.handler"/>
628+
</service>
629+
630+
<serviceid="App\HandlerCollection">
631+
<!-- inject all services tagged with app.handler as first argument-->
632+
<argumenttype="tagged_iterator"tag="app.handler">
633+
<exclude>App\Handler\Three</exclude>
634+
</argument>
635+
</service>
636+
</services>
637+
</container>
638+
639+
..code-block::php
640+
641+
// config/services.php
642+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
643+
644+
return function(ContainerConfigurator $configurator) {
645+
$services = $configurator->services();
646+
647+
// ...
648+
649+
// This is the service we want to exclude, even if the 'app.handler' tag is attached
650+
$services->set(App\Handler\Three::class)
651+
->tag('app.handler')
652+
;
653+
654+
$services->set(App\HandlerCollection::class)
655+
// inject all services tagged with app.handler as first argument
656+
->args([tagged_iterator('app.handler', exclude: [App\Handler\Three::class])])
657+
;
658+
};
659+
660+
..versionadded::6.1
661+
662+
The ``exclude`` option was introduced in Symfony 6.1.
663+
594664
..seealso::
595665

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp