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] Allow to choose an index for tagged collection#30257

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

Conversation

@XuruDragon
Copy link

@XuruDragonXuruDragon commentedFeb 15, 2019
edited
Loading

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#29203
LicenseMIT
Doc PRsymfony/symfony-docs#11009

This is the continuity of the PR#29598

Add a way to specify an index based on a tag attribute when injecting a tag collection into services, but also a a way to fallback to a static method on the service class.

services:foo_service:class:Footags:      -foofoo_service_tagged:class:Bararguments:      -!taggedtag:'foo'index_by:'tag_attribute_name'default_index_method:'static_method'
<?xml version="1.0" ?><containerxmlns="http://symfony.com/schema/dic/services"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">  <services>    <serviceid="foo"class="Foo">        <tagname="foo_tag" />    </service>    <serviceid="foo_tagged_iterator"class="Bar"public="true">      <argumenttype="tagged"tag="foo_tag"index-by="tag_attribute_name"default-index-method="static_method" />    </service>  </services></container>

Tasks

  • Support PHP loader/dumper
  • Support YAML loader/dumper
  • Support XML loader/dumper (and update XSD too)
  • Add tests
  • Documentation

deguif, yceruto, Pierstoval, zmitic, patrykwozinski, and TomasVotruba reacted with thumbs up emoji
Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

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

Cool, almost ready! Just a few comments to improve tests.
Please see fabbot report also.

@XuruDragonXuruDragonforce-pushed thedi-tagged-iterrator branch 2 times, most recently fromc84f9b9 tod18fd9aCompareFebruary 15, 2019 14:20
@nicolas-grekasnicolas-grekasforce-pushed thedi-tagged-iterrator branch 2 times, most recently from22dfaf3 toa6ffe83CompareFebruary 15, 2019 14:36
@nicolas-grekas
Copy link
Member

(FYI, failures unrelated)

@XuruDragon
Copy link
Author

PR to the documentation added

nicolas-grekas, deguif, and patrykwozinski reacted with thumbs up emoji

@XuruDragon
Copy link
Author

Code rebased on master, CI fixed

Copy link
Member

@xabbuhxabbuh left a comment

Choose a reason for hiding this comment

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

👍 with a minor comment

@nicolas-grekas
Copy link
Member

Thank you@XuruDragon.

@nicolas-grekas
Copy link
Member

And thank you@deguif!

@nicolas-grekasnicolas-grekas merged commit101bfd7 intosymfony:masterFeb 22, 2019
nicolas-grekas added a commit that referenced this pull requestFeb 22, 2019
…ged collection (deguif, XuruDragon)This PR was merged into the 4.3-dev branch.Discussion----------[DependencyInjection] Allow to choose an index for tagged collection| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#29203| License       | MIT| Doc PR        |symfony/symfony-docs#11009This is the continuity of the PR#29598Add a way to specify an index based on a tag attribute when injecting a tag collection into services, but also a a way to fallback to a static method on the service class.```yamlservices:  foo_service:    class: Foo    tags:      - foo  foo_service_tagged:    class: Bar    arguments:      - !tagged          tag: 'foo'          index_by: 'tag_attribute_name'          default_index_method: 'static_method'``````xml<?xml version="1.0" ?><container xmlns="http://symfony.com/schema/dic/services"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://symfony.com/schema/dic/serviceshttp://symfony.com/schema/dic/services/services-1.0.xsd">  <services>    <service>        <tag name="foo_tag" />    </service>    <service public="true">      <argument type="tagged" tag="foo_tag" index-by="tag_attribute_name" default-index-method="static_method" />    </service>  </services></container>```Tasks* [x]  Support PHP loader/dumper* [x]  Support YAML loader/dumper* [x]  Support XML loader/dumper (and update XSD too)* [x]  Add tests* [x]  DocumentationCommits-------101bfd7 [DI] change name to tag + add XMl support + adding yaml/xml tests845d3a6 Allow to choose an index for tagged collection
@enumag
Copy link
Contributor

@stof
Copy link
Member

@enumag the use case you described in your comment is the use case where a ServiceLocator is what you need. Se#30348 which uses the feature of that PR to simplify configuring the ServiceLocator.

@enumag
Copy link
Contributor

@stof Thanks! Indeed that's exactly what I need.

nicolas-grekas added a commit that referenced this pull requestMar 15, 2019
…or service in an injected service locator argument (XuruDragon, nicolas-grekas)This PR was merged into the 4.3-dev branch.Discussion----------[DependencyInjection] Add ability to define an index for service in an injected service locator argument| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | n/a| License       | MIT| Doc PR        | in progress /  symfony/symfony-docs#...It's more or less the same thing then the PR#30257 but for a service locator argumentAdd a simple way to specify an index based on a tag attribute to simplify retrieving a specific service when injecting a service locator as argument into services, but also a way to fallback to a static method on the service class.Yaml:```yamlservices:  foo_service:    class: Foo    tags:      - {name: foo_tag, key: foo_service}  foo_service_tagged:    class: Bar    arguments:      - !tagged_locator          tag: 'foo_tag'          index_by: 'key'          default_index_method: 'static_method'```XML:```xml<?xml version="1.0" ?><container xmlns="http://symfony.com/schema/dic/services"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://symfony.com/schema/dic/serviceshttp://symfony.com/schema/dic/services/services-1.0.xsd">  <services>    <service>        <tag name="foo_tag" key="foo_service" />    </service>    <service public="true">      <argument type="tagged_locator" tag="foo_tag" index-by="key" default-index-method="static_method" />    </service>  </services></container>```PHP:```php// config/services.phpuse Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;$container->register(Foo::class)        ->addTag('foo_tag', ['key' => 'foo_service']);$container->register(App\Handler\HandlerCollection::class)         // inject all services tagged with app.handler as first argument         ->addArgument(new ServiceLocatorArgument(new TaggedIteratorArgument('app.handler', 'key')));```Usage:```php// src/Handler/HandlerCollection.phpnamespace App\Handler;use Symfony\Component\DependencyInjection\ServiceLocator;class HandlerCollection{     public function __construct(ServiceLocator $serviceLocator)     {           $foo = $serviceLocator->get('foo_service'):     }}```Tasks* [x]  Support PHP loader/dumper* [x]  Support YAML loader/dumper* [x]  Support XML loader/dumper (and update XSD too)* [x]  Add tests* [x]  DocumentationCommits-------cb3c56b Support indexing tagged locators by FQCN as fallback250a2c8 [DI] Allow tagged_locator tag to be used as an argument
@nicolas-grekasnicolas-grekas modified the milestones:next,4.3Apr 30, 2019
@fabpotfabpot mentioned this pull requestMay 9, 2019
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull requestSep 24, 2019
…or service locators (Anthony MARTIN)This PR was submitted for the master branch but it was merged into the 4.3 branch instead (closes#11042).Discussion----------[DependencyInjection] Doc for Allow to choose an index for service locatorsHere is the doc for the new feature implemented in : [symfony/symfony#30348](symfony/symfony#30348) that follow the feature [symfony/symfony#30257](symfony/symfony#30257)Commits-------d63c298 [DependencyInjection] Doc for Allow to choose an index for service locator collection
wouterj added a commit to symfony/symfony-docs that referenced this pull requestOct 4, 2020
…n index for tagged collection (Anthony MARTIN)This PR was submitted for the master branch but it was merged into the 4.4 branch instead.Discussion----------[DependencyInjection] Doc for #30257 Allow to choose an index for tagged collectionHere is the doc for the new feature implemented in :symfony/symfony#30257Commits-------980b3d3 [DependencyInjection] Doc for #30257 Allow to choose an index for tagged collection
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@stofstofstof left review comments

@xabbuhxabbuhxabbuh approved these changes

@chalasrchalasrchalasr approved these changes

+2 more reviewers

@TobionTobionTobion requested changes

@deguifdeguifdeguif approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.3

Development

Successfully merging this pull request may close these issues.

9 participants

@XuruDragon@nicolas-grekas@enumag@stof@Tobion@deguif@xabbuh@chalasr@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp