Support Symfony #[AutowireLocator] attribute#420
Support Symfony #[AutowireLocator] attribute#420RafaelKr wants to merge 5 commits intophpstan:1.4.xfrom
Conversation
83ef507 to
5984d62
Compare
|
Edit: Got it. |
9334602 to
13edbbc
Compare
…PrivateServiceRule We now create an AutowireLocator instance and check if the service exists there. This also removes a lot of nested foreach loops and thus decreases the complexity of the isAutowireLocatorService method a lot. https://symfony.com/blog/new-in-symfony-6-4-autowirelocator-and-autowireiterator-attributes
fe2a56d to
4ef06e1
Compare
|
I'll add some tests later, besides from that it's ready for review. Btw: I tried to rename the branch of my Repo to feat/autowirelocator, but it wasn't possible without losing the connection to this PR, the PR showed the branch was deleted in that case. |
This allows us to share the logic for other rules
ec48673 to
b2c2416
Compare
|
I also added tests now, but I have no idea how to resolve the failing lint and test checks. If someone can resolve those we're ready to merge from my side 🚀 |
|
I also noticed it only works when we're using Constructor property promotion, so when specifying It won't work when Is this a problem in practice? |
|
Hi, I can't review this when the build isn't green. |
I implemented initial support for the
#[AutowireLocator]attribute. See https://symfony.com/blog/new-in-symfony-6-4-autowirelocator-and-autowireiterator-attributesThe simple syntax is supported now:
It also supports when classes are specified via string:
#[AutowireLocator(['App\FooHandler'])]The advanced syntax described in the blog post is
notalso supportedyetnow:#[AutowireLocator([ 'foo' => FooHandler::class, 'bar' => new SubscribedService(type: 'string', attributes: new Autowire('%some.parameter%')), 'optionalBaz' => '?'.BazHandler::class, ])] private ContainerInterface $handlers,Maybe someone else wants to figure this out. Unfortunately I have no more time left to do it in the coming days.Edit 2: I just found out how I can both simplify this a lot and implement the advanced syntax by just creating an instance of the AutowireLocator attribute. And I'll move this to
AutowireLoaderServiceMapFactoryso it will be also available forPHPStan\Rules\Symfony\ContainerInterfaceUnknownServiceRule.closes #411