Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DependencyInjection] Deprecate #[TaggedIterator] and #[TaggedLocator] #54371

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2024

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Mar 21, 2024

Q A
Branch? 7.1
Bug fix? no
New feature? no
Deprecations? yes
Issues Planned in #51832
License MIT

#[TaggedIterator] and #[TaggedLocator] attributes are replaced by #[AutowireIterator] and #[AutowireLocator], for naming consistency with all #[Autowire*] attributes.

@GromNaN GromNaN added this to the 7.1 milestone Mar 21, 2024
@carsonbot carsonbot changed the title [DependencyInjection] Deprecate #[TaggedIterator] and #[TaggedLocator] Deprecate #[TaggedIterator] and #[TaggedLocator] Mar 21, 2024
@carsonbot carsonbot changed the title Deprecate #[TaggedIterator] and #[TaggedLocator] [DependencyInjection] Deprecate #[TaggedIterator] and #[TaggedLocator] Mar 21, 2024
@stof
Copy link
Member

stof commented Mar 21, 2024

Tests covering those 2 attributes must be updated to be marked as @group legacy (and we need to ensure that tests covering those deprecated attributes are not used to also cover other parts that should remain tested after their removal, to avoid loosing coverage, splitting such tests in a legacy test and a non-legacy one instead)

@GromNaN GromNaN force-pushed the deprecate-tagged-attributes branch 3 times, most recently from 65d3a3a to 437bf87 Compare March 21, 2024 18:36
Copy link
Member Author

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

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

All tests updated. I think the CI errors are not related to this change.

$this->assertTrue($locator->has('locator1'));
$this->assertInstanceOf(ServiceLocator::class, $argLocator = $locator->get('locator1'));
$this->assertCount(2, $argLocator);
$this->assertTrue($argLocator->has('bar'));
$this->assertTrue($argLocator->has('baz'));

$this->assertSame(iterator_to_array($argIterator), [$argLocator->get('bar'), $argLocator->get('baz')]);
}

public function testAutowireIteratorAndAutowireLocatorAttributes()
Copy link
Member Author

Choose a reason for hiding this comment

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

I've split the test in legacy and new attributes. There is no expectDeprecation so the test passes with symfony/dependency-injection 7.0

@smnandre
Copy link
Member

smnandre commented Mar 22, 2024

Should this be more general... i fear this could feel a bit of a half seated DX too, with

return function (ContainerConfigurator $container): void {

    $services->set(Two::class)
        ->tag('app.handler', ['key' => 'handler_two']);

    $services->set(App\HandlerCollection::class)
        ->args([
            // 2nd argument is the index attribute name
            tagged_iterator('app.handler', 'key'),
        ])
    ;
};

Versus

class HandlerCollection
{
    public function __construct(
        #[AutowireIterator('app.handler', indexAttribute: 'key')]
        iterable $handlers
    ) {
    }
}

// ... 

#[AsTaggedItem(index: 'handler_one', priority: 10)]
class One
{
    // ...
}

@GromNaN
Copy link
Member Author

GromNaN commented Mar 22, 2024

You mean tagged_iterator is closer to #[TaggedIterator] than #[AutowireIterator].

But #[AutowireIterator] is part of the #[Autowire] attribute.

In terms of DX, we currently have 2 attributes that does the exact same thing.

@smnandre
Copy link
Member

I totally understand your motive here :)

What i feel is a lack of consistency / predictability here, that could be difficult to explain / document / etc.

Config Locator Item
Attribute AutowireLocator AsTaggedItem
Config tagged_locator tag

So maybe we could rename AsTaggedItem too (as it's only used for tagged locator / iterator) ?

AutowiredItem ?

@stof
Copy link
Member

stof commented Mar 25, 2024

The name AsAutowiredItem would be misleading, because AsTaggedItem is unrelated to autowiring. It is autoconfiguration that applies the tag on the item with those properties, not autowiring. And this As* naming convention is the one followed by autoconfiguration attributes.

@javiereguiluz javiereguiluz added the ❄️ Feature Freeze Important Pull Requests to finish before the next Symfony "feature freeze" label Apr 2, 2024
@GromNaN GromNaN force-pushed the deprecate-tagged-attributes branch 2 times, most recently from 8514c76 to aa85bd4 Compare April 12, 2024 12:58
@GromNaN GromNaN force-pushed the deprecate-tagged-attributes branch from aa85bd4 to 4bc6bed Compare April 12, 2024 13:49
@GromNaN GromNaN requested a review from nicolas-grekas April 25, 2024 21:31
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

Let's do this.
We cannot use the term "autowire" when doing explicit config so keeping tagged_iterator for the config is legit.
What would be best regarding naming is having AutowireTaggedIterator. BUT, this feels like overhead.

@fabpot
Copy link
Member

fabpot commented May 2, 2024

Thank you @GromNaN.

@GromNaN GromNaN deleted the deprecate-tagged-attributes branch May 2, 2024 09:03
@fabpot fabpot mentioned this pull request May 2, 2024
fabpot added a commit that referenced this pull request Jun 20, 2025
…#[TaggedLocator]` attributes (GromNaN)

This PR was merged into the 8.0 branch.

Discussion
----------

[DependencyInjection] Remove `#[TaggedIterator]` and `#[TaggedLocator]` attributes

| Q             | A
| ------------- | ---
| Branch?       | 8.0
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Issues        | -
| License       | MIT

The new attributes `#[AutowireLocator]` and `#[AutowireIterator]` were introduced in Symfony 6.4 by #51392 and #51832.
These replace the previous attributes `#[TaggedIterator]` and `#[TaggedLocator]` which were introduced in Symfony 5.4 by #40406 and subsequently deprecated in 7.1 by #54371

Commits
-------

c096714 Remove TaggedIterator and TaggedLocator attributes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DependencyInjection Deprecation ❄️ Feature Freeze Important Pull Requests to finish before the next Symfony "feature freeze" Status: Reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants