Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Support for ServiceLocator #151

Merged
merged 2 commits into from
Apr 27, 2021
Merged

Support for ServiceLocator #151

merged 2 commits into from
Apr 27, 2021

Conversation

andrey-bondar
Copy link
Contributor

@andrey-bondar andrey-bondar commented Apr 26, 2021

Now when private services are fetching from Psr\Container\ContainerInterface::get(), an error "Service "%s" is private" occurred.

But Symfony has ServiceLocators in order to define smaller containers with public access to services.

This PR solves error "Service "%s" is private" when service is fetching from ServiceLocator.

@ondrejmirtes
Copy link
Member

Hi, what errors it resolves? Please attach a test too.

@andrey-bondar
Copy link
Contributor Author

@ondrejmirtes I've attached tests

@ondrejmirtes ondrejmirtes merged commit e4b9ea9 into phpstan:master Apr 27, 2021
@ondrejmirtes
Copy link
Member

Thank you!

@Wirone
Copy link
Contributor

Wirone commented Feb 7, 2022

Sorry for digging the old issue @ondrejmirtes but I'm implementing Symfony extension in our app and I got "Service ... is private" errors. I've found out that our app uses service locators BUT they are not extending Symfony\Component\DependencyInjection\ServiceLocator but only implementing Psr\Container\ContainerInterface. I can't extend Symfony's ServiceLocator because we already have custom implementation of get(), so all I could do is implementing Symfony\Contracts\Service\ServiceProviderInterface (which is also implemented in ServiceLocator). Unfortunately it won't be resolved properly in PHPStan\Rules\Symfony\ContainerInterfacePrivateServiceRule::processNode() since it checks explicitly for ServiceLocator.

What do you think, is it possible to change condition ($isServiceLocator$isServiceProvider) so raw ServiceProviderInterface would be supported instead of concrete ServiceLocator?

@ondrejmirtes
Copy link
Member

Feel free to send a PR with a test and a fix and we'll see (mostly what @lookyman will say about it :))

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants