Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[DependencyInjection] Inherit "public" option when creating aliases with the auto_alias tag#41209
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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
| $aliasId =$container->getParameterBag()->resolveValue($tag['format']); | ||
| if ($container->hasDefinition($aliasId) ||$container->hasAlias($aliasId)) { | ||
| $container->setAlias($serviceId,newAlias($aliasId,true)); | ||
| $container->setAlias($serviceId,newAlias($aliasId,$container->getDefinition($serviceId)->isPublic())); |
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.
this should come with a BC layer that triggers a deprecation when the alias is used as a public one while the target is private
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.
@nicolas-grekas Done, ifpublic is not explicitly set it will default totrue and trigger a deprecation. In the future the deprecation can be removed andfalse set as the default.
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.
I was thinking about something likehttps://symfony.com/blog/new-in-symfony-5-1-deprecate-public-services-into-private-services but for aliases. Not sure how. /cc@fancyweb
nicolas-grekas commentedSep 9, 2021
Thanks for the PR. I decided to submit#42959 instead. Please have a look. |
HypeMC commentedSep 9, 2021
@nicolas-grekas Great, thank you 😄 |
…ault (nicolas-grekas)This PR was merged into the 5.4 branch.Discussion----------[DependencyInjection] Make auto-aliases private by default| Q | A| ------------- | ---| Branch? | 5.4| Bug fix? | no| New feature? | no| Deprecations? | yes| Tickets | -| License | MIT| Doc PR | -Replaces#41209Before, this creates a public autoalias:```yaml app.lock: tags: - { name: auto_alias, format: "app.%database_type%_lock" }```After, this creates a public autoalias:```yaml app.lock: public: true tags: - { name: auto_alias, format: "app.%database_type%_lock" }```Omitting `public: true` will trigger a deprecation warning when the alias is accessed from `$container->get()`. In 6.0, the alias will be private by default if `public: true` is not set.Commits-------679f25e [DependencyInjection] Make auto-aliases private by default
Currently when using the
auto_aliastag, the aliases created are alwayspublic. With this PR the public option is inherited from the definition: