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

Appearance settings

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

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Conversation

HypeMC
Copy link
Member

@HypeMC HypeMC commented May 13, 2021

Q A
Branch? 5.x
Bug fix? no
New feature? yes
Deprecations? no
Tickets -
License MIT
Doc PR TODO

Currently when using the auto_alias tag, the aliases created are always public. With this PR the public option is inherited from the definition:

App\Service\SomeInterface:
    public: true # The alias inherits the public option
    tags:
        - { name: auto_alias, format: '%my_class%' }

@@ -33,7 +33,7 @@ public function process(ContainerBuilder $container)

$aliasId = $container->getParameterBag()->resolveValue($tag['format']);
if ($container->hasDefinition($aliasId) || $container->hasAlias($aliasId)) {
$container->setAlias($serviceId, new Alias($aliasId, true));
$container->setAlias($serviceId, new Alias($aliasId, $container->getDefinition($serviceId)->isPublic()));
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

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

@nicolas-grekas Done, if public is not explicitly set it will default to true and trigger a deprecation. In the future the deprecation can be removed and false set as the default.

Copy link
Member

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 like https://symfony.com/blog/new-in-symfony-5-1-deprecate-public-services-into-private-services but for aliases. Not sure how. /cc @fancyweb

@nicolas-grekas
Copy link
Member

Thanks for the PR. I decided to submit #42959 instead. Please have a look.

@HypeMC HypeMC deleted the auto-alias-private branch September 9, 2021 09:35
@HypeMC
Copy link
Member Author

HypeMC commented Sep 9, 2021

@nicolas-grekas Great, thank you 😄

nicolas-grekas added a commit that referenced this pull request Sep 10, 2021
…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 #41209

Before, 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.