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] Deprecate ContainerInterface aliases #35879

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

fancyweb
Copy link
Contributor

@fancyweb fancyweb commented Feb 26, 2020

Q A
Branch? master
Bug fix? no
New feature? no
Deprecations? yes
Tickets -
License MIT
Doc PR -

Defining those aliases makes it harder to detect problems when you use !tagged_locator or any service locator with autowiring since the global service container is always injected. Moreover, should we encourage passing the global service container easily? Shouldn't it be more "explicit"? I think that by default, those aliases should not exist.

However, that means we will have to reintroduce code to hook the global service container in our own code base since some part rely on it (eg: FWB AbstractController::setContainer). WDYT? 🤷‍♂

@michaljusiega
Copy link
Contributor

Will there be a replacement option?

@fancyweb
Copy link
Contributor Author

Yes, you would have to define those aliases in your project.

@nicolas-grekas
Copy link
Member

However, that means we will have to reintroduce code to hook the global service container in our own code base since some part rely on it (eg: FWB AbstractController::setContainer)

I'm not sure what you mean here: AbstractController is a service subscriber, it doesn't use the main container.

Looks good to me otherwise (I didn't review the details yet.)

@michaljusiega
Copy link
Contributor

Yes, you would have to define those aliases in your project.

So, please show me a small example because I'm not sure of these changes ... and if it works, why remove it?

@fancyweb
Copy link
Contributor Author

I'm not sure what you mean here: AbstractController is a service subscriber, it doesn't use the main container.

Indeed, that's a bad example 😅 What I mean is that our own code (untested code since all tests passes) might rely on those aliases and we will need to fix that.

So, please show me a small example because I'm not sure of these changes ...

For example, in YAML:

Psr\Container\ContainerInterface:
    alias: "service_container"

Check https://symfony.com/doc/current/service_container/alias_private.html#aliasing.

and if it works, why remove it?

For the reasons I described in the PR description.

@nicolas-grekas nicolas-grekas added this to the next milestone Feb 27, 2020
@nicolas-grekas
Copy link
Member

What I mean is that our own code (untested code since all tests passes) might rely on those aliases and we will need to fix that

That shouldn't be the case - we don't use autowiring in core. Did you find any?

@fancyweb fancyweb force-pushed the di-deprecate-service-container-aliases branch 2 times, most recently from 8225445 to 76172b8 Compare February 28, 2020 11:53
@@ -148,6 +152,9 @@ private function createContainer($sessionStorageOptions)
$pass = new AddSessionDomainConstraintPass();
$pass->process($container);

$container->setDefinition('.service_subscriber.fallback_container', new Definition(Container::class));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

That test class does not compile the container so the RegisterServiceSubscribersPass pass is not executed. Consequently, services that have Psr\Container\ContainerInterface as an argument that would normally be replaced by a smaller locator tag end up relying on the autowired global container, and on the deprecated alias, so they trigger a deprecation.

@fancyweb fancyweb force-pushed the di-deprecate-service-container-aliases branch from 76172b8 to 42fe4fc Compare March 26, 2020 14:11
@nicolas-grekas
Copy link
Member

Rebase needed.
Ping @symfony/mergers meanwhile.

@fancyweb
Copy link
Contributor Author

fancyweb commented Apr 1, 2020

TODO: waiting for #36295 because tests can't pass atm.

@fancyweb fancyweb force-pushed the di-deprecate-service-container-aliases branch from 42fe4fc to 6162ca8 Compare April 1, 2020 07:33
@nicolas-grekas
Copy link
Member

Thank you @fancyweb.

reviewtypo3org pushed a commit to TYPO3/typo3 that referenced this pull request Jul 1, 2021
Account for the symfony deprecation in
symfony/symfony#35879
which deprecated the default alias for Psr\Container\ContainerInterface
and flooded our deprecaton logs since #94269.

This deprecation is intended to help with symfony service locators
(which we do not use), but would break our usecases once we update to
symfony v6 as TYPO3 core and extensions rely on service_container
autowiring for the PSR ContainerInterface alias.

Releases: master
Resolves: #94453
Related: #94269
Change-Id: I0599b3a8a5640faf2fac5094175ae2a6fb37a0a3
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/69678
Tested-by: Oliver Bartsch <bo@cedev.de>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Benjamin Franzke <bfr@qbus.de>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Benjamin Franzke <bfr@qbus.de>
TYPO3IncTeam pushed a commit to TYPO3-CMS/core that referenced this pull request Jul 1, 2021
Account for the symfony deprecation in
symfony/symfony#35879
which deprecated the default alias for Psr\Container\ContainerInterface
and flooded our deprecaton logs since #94269.

This deprecation is intended to help with symfony service locators
(which we do not use), but would break our usecases once we update to
symfony v6 as TYPO3 core and extensions rely on service_container
autowiring for the PSR ContainerInterface alias.

Releases: master
Resolves: #94453
Related: #94269
Change-Id: I0599b3a8a5640faf2fac5094175ae2a6fb37a0a3
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/69678
Tested-by: Oliver Bartsch <bo@cedev.de>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Benjamin Franzke <bfr@qbus.de>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Benjamin Franzke <bfr@qbus.de>
mpdude added a commit to mpdude/FriendsOfBehat_SymfonyExtension that referenced this pull request Nov 24, 2022
This is necessary as of Symfony 6.0 due to symfony/symfony#35879.
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.

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