-
Notifications
You must be signed in to change notification settings - Fork 93
AutowireLocator does not work well #440
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
Comments
I don't get it. Please explain the problem. |
edit I just noticed this issue should be move to phpstan/phpstan-symfony In Symfony, you can type hint a parameter with Example: class Foo
{
public function __construct(
#[AutowireLocator(MyInterface::class)]
private ContainerInterface $container,
) {}
public function consume(): void
{
$this->container->get(Foo::class);
}
} Here, in If you look at the the dumped definition: <service id="App\Reproducer\Consumer" class="App\Reproducer\Consumer" autowire="true" autoconfigure="true">
<argument type="service" id=".service_locator.ExRZJjZ"/>
</service>
<service id=".service_locator.ExRZJjZ" class="Symfony\Component\DependencyInjection\ServiceLocator">
<tag name="container.service_locator"/>
<argument type="collection">
<argument key="App\Reproducer\Foo" type="service_closure" id="App\Reproducer\Foo"/>
</argument>
</service> You can also specified some service ids: public function __construct(
#[AutowireLocator([
FooHandler::class,
BarHandler::class,
])]
private ContainerInterface $handlers,
) {
} If I'm not clear enough, you can read the symfony doc When running phpstan on this code, it thinks the container is the whole symfony container. So, when a container is injected, phpstan should check if it's the whole |
This belongs to phpstan-symfony. |
Yes, that what I said in my latest comment. I have no right to move this issue. Could you do it for me? Thanks |
When we inject a ServiceLocator, the extension does not understand that.
It thinks it's the full container, but it's not. It's a specialed container.
I made a full reproducer:
lyrixx/test@e172840#r154945352
(ref symfony/symfony#60096 (comment))
The text was updated successfully, but these errors were encountered: