-
Notifications
You must be signed in to change notification settings - Fork 90
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
Symfony 6 Rules about ContainerInterface #636
Comments
If I recall correctly, this was due to interface not being a valid service name anymore. This applied only to PHP files (configs). If you add aliases to your YAML files like these, it's another way to upgrade, but it only reverts the upgrade path, so not really way to go: services:
Symfony\Component\DependencyInjection\ContainerInterface: '@service_container'
Psr\Container\ContainerInterface: '@service_container' What's the use case for service using container? Those should be refactored to require particular services over whole container. |
It was to use Locators (bad use of the interface, I guess but symfony docs keep showing this in example, event for 7.x) and some very specific cases but I'm refactoring it to use But as Symfony keep showing |
Sounds good 👍 Could you share a diff how this change should look like? |
Sure And the diff should be something like that (including both - use Psr\Container\ContainerInterface;
// OR
- use Symfony\Component\DependencyInjection\ContainerInterface
+ use Symfony\Contracts\Service\ServiceProviderInterface;
class MyClass
{
public function __construct(
#[TaggedLocator(tag: 'app:tag-locator')]
- private readonly ContainerInterface $locator,
+ private readonly ServiceProviderInterface $locator
) {}
} Not sure if it's possible but to make sure the |
Thanks! Looks good to target 6.0. Checking Would you like to contribute this feature? |
I could take a look and let you know if I can do it in a few days, yeah |
I'm upgrading a few project from Symfony 5.4 to 6.4. I first try to upgrade to Symfony 6.0 and I don't quite understand the rules about
ContainerInterface
.What's is this supposed to change ?
If we use the interface directly it doesn't change anything so shouldn't it be a class rename from
ContainerInterface
(both PSR and Symfony) intoSymfony\Contracts\Service\ServiceProviderInterface
? (not sure about that as ServiceLocator are not the only use for injecting ContainerInterface)Or at least add the following definitions ?
The text was updated successfully, but these errors were encountered: