-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[DependencyInjection] Add AsAlias attribute #49411
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
Conversation
nicolas-grekas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice thank you!
src/Symfony/Component/DependencyInjection/Attribute/AsAlias.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Loader/FileLoader.php
Outdated
Show resolved
Hide resolved
649aac1 to
3fcf97a
Compare
|
Changes done, thanks for the review 🙂 |
src/Symfony/Component/DependencyInjection/Tests/Loader/FileLoaderTest.php
Outdated
Show resolved
Hide resolved
3fcf97a to
a82aeb1
Compare
kbond
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
eea6905 to
fe63d39
Compare
fe63d39 to
80d8cc1
Compare
|
Thank you @alanpoulain. |
| ]]; | ||
| yield 'Multiple with id' => ['PrototypeAsAlias/{WithAsAliasIdMultipleInterface,AliasBarInterface,AliasFooInterface}.php', [ | ||
| AliasBarInterface::class => new Alias(WithAsAliasIdMultipleInterface::class), | ||
| AliasFooInterface::class => new Alias(WithAsAliasIdMultipleInterface::class), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the AliasFooInterface being registered? Is it because of the WithAsAliasIdMultipleInterface class being the only one implementing this interface?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I think it's the right behavior, don't you think so? The other possibility would be to prevent the singly implemented interface registration if there is an AsAlias attribute on the class.
Add the
AsAliasattribute for defining an alias on a service:If no parameter is used in the attribute and if there is only one implemented interface, it takes this interface for the alias:
is equivalent to:
This implementation follows @nicolas-grekas suggestion in #49361: doing it in
FileLoader::registerClasses()allows to check if there is no collision.