Skip to content
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

TaggedLocator attribute does not work in controller constructor #49082

Open
lyrixx opened this issue Jan 24, 2023 · 4 comments
Open

TaggedLocator attribute does not work in controller constructor #49082

lyrixx opened this issue Jan 24, 2023 · 4 comments

Comments

@lyrixx
Copy link
Member

lyrixx commented Jan 24, 2023

Symfony version(s) affected

6.2.* (and maybe other)

Description

A wrong Container is injected when using #[TaggedLocator('XXX')] in an argument of a controller constructor

How to reproduce

add this controller

class AController extends AbstractController
{
    public function __construct(
        #[TaggedLocator('foobar')]
        private readonly ContainerInterface $foo,
    ) {
    }

    #[Route('/', name: 'app_a')]
    public function index(
    ): JsonResponse
    {
        dd($this->foo);
        return $this->json([
            'message' => 'Welcome to your new controller!',
            'path' => 'src/Controller/AController.php',
        ]);
    }
}

Possible Solution

We can work-arround this issue with the following constructor:

     public function __construct(
         #[TaggedLocator('foobar')]
-        private readonly ContainerInterface $foo,
+        private readonly ServiceLocator $foo,
     ) {
     }

but ...

Additional Context

I guess - there is a conflict with the "ServiceSubscriberInterface"

image

@lyrixx lyrixx added the Bug label Jan 24, 2023
@lyrixx lyrixx changed the title TaggedLocator attribute does not work on constructor controller TaggedLocator attribute does not work in controller constructor Jan 24, 2023
@alexandre-daubois

This comment was marked as off-topic.

@lyrixx

This comment was marked as off-topic.

@alexandre-daubois

This comment was marked as off-topic.

@lyrixx

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants