Skip to content

[HttpKernel][Bug] ServiceValueResolver fails if controller namespace starts with a backslash in routing. #26772

Closed
@mathieutu

Description

@mathieutu
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 4.0.

Hi,
I've seen a problem when configuring my routes:

Controller "App\Controllers\Foo" requires that you provide a value for the "$foo" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one.

# config/routes.yaml
foo:
    methods: POST
    path: /foo
    controller: \App\Controllers\Foo
// src/Controllers/Foo.php
class Foo
{
    public function __invoke(FooService $foo, Request $request)
    {
        // ...
    }
}

The services.yaml is properly configured: Foo is tagged as a 'controller.service_arguments' and FooService is correctly autowired, and can be seen in php bin/console debug:autowiring.

The service locator is correctly generated in container cache.

When debugging, I've seen that in the \Symfony\Component\HttpKernel\Controller\ArgumentResolver\ServiceValueResolver::supports method, the controller passed to the route ("\App\Controllers\Foo") is searched in container factories (["App\Controllers\Foo" => (...)]) and not found because of the first backslash of the namespace.

The router find the proper controller with this backslash, so in my opinion the ServiceValueResolver should not fail at this point.

The following PR fixes this issue: #26773

Thanks for you work.

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