Skip to content

TaggedLocator attribute does not work in controller constructor  #49082

Closed
@lyrixx

Description

@lyrixx

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions