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] Fix TaggedLocator attribute without indexAttribute argument#42019

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

@lbae
Copy link
Contributor

@lbaelbae commentedJul 7, 2021

QA
Branch?5.3
Bug fix?yes
New feature?no
Deprecations?no
Tickets
LicenseMIT
Doc PR

The new TaggedLocator attribute does not index services correctly without theindexAttribute argument

Example

publicfunction__construct(    #[TaggedLocator('app.tag')]ServiceLocator$serviceLocator) {// ...}

Expected

$serviceLocator->getProvidedServices();// [//    "App\Service1" => "..."//    "App\Service2" => "..."// ]$serviceLocator->has(App\Service1::class);// true$serviceLocator->get(App\Service1::class);// Instance of App\Service1

Actual

$services =$serviceLocator->getProvidedServices();// [//    0 => [...]//    1 => [...]// ]$serviceLocator->has(App\Service1::class);// false$serviceLocator->get(App\Service1::class);// Exception

Same issue with ContainerInterface instead of ServiceLocator

Proposed solution

This fix allows services to be indexed by their fully qualified name instead of a numeric index ifindexAttribute argument is not provided.

The solution is oriented towards the implemenation in the YamlFileLoader (Symfony\Component\DependencyInjection\Loader\YamlFileLoader). The YamlFileLoader fulfills the expected behaviour above:

// Symfony\Component\DependencyInjection\Loader\YamlFileLoader// Line 850$forLocator ='tagged_locator' ===$value->getTag();// ...// Line 857$argument =newTaggedIteratorArgument($argument['tag'],$argument['index_by'] ??null,$argument['default_index_method'] ??null,$forLocator,$argument['default_priority_method'] ??null);

mbaeuerle reacted with eyes emoji
With this fix, services in service locators are indexed by their fully qualified name instead of a numeric index if `indexAttribute` argument is not provided
@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has acontribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (seehttps://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (seehttps://symfony.com/releases)
  • Features and deprecations must be submitted against the 5.4 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@lbae
Copy link
ContributorAuthor

lbae commentedJul 7, 2021

I'm not sure about the failed coding standards test.

The test fails on the exception message of AutowiringFailedException, which was not touched in this PR

@derrabus
Copy link
Member

which was not touched in this PR

If you didn't break it, you don't have to fix it. ✌🏻

@nicolas-grekas
Copy link
Member

Good catch, thanks@lbae.

@nicolas-grekasnicolas-grekas merged commite33714b intosymfony:5.3Jul 10, 2021
@fabpotfabpot mentioned this pull requestJul 26, 2021
svetlana-s pushed a commit to svetlana-gor/symfony-demo-app that referenced this pull requestJan 14, 2022
svetlana-s pushed a commit to svetlana-gor/symfony-demo-app that referenced this pull requestJan 14, 2022
svetlana-s pushed a commit to svetlana-gor/symfony-demo-app that referenced this pull requestJan 14, 2022
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@dunglasdunglasAwaiting requested review from dunglasdunglas is a code owner

Assignees

No one assigned

Projects

None yet

Milestone

5.3

Development

Successfully merging this pull request may close these issues.

4 participants

@lbae@carsonbot@derrabus@nicolas-grekas

[8]ページ先頭

©2009-2025 Movatter.jp