Closed
Description
Symfony version(s) affected
6.4.0
Description
Currently I usually define my routes this way:
#Route(path: '/foobar', name: self::class)
class FoobarController
{
}
This way I can use the FQCN to generate the controller's URL:
$this->urlGenerator->generate(FoobarController::class)
This definition does not work in Symfony 6.4.0
anymore:
[Symfony\Component\Config\Exception\LoaderLoadException]
Route alias "App\Controller\FoobarController" can not reference itself in src/Controller (which is being imported from "config/routes.yaml"). Make sure there is a loader supporting the "annotation" type.
Exception trace:
at vendor\symfony\config\Loader\FileLoader.php:182
Symfony\Component\Config\Loader\FileLoader->doImport() at vendor\symfony\config\Loader\FileLoader.php:98
Symfony\Component\Config\Loader\FileLoader->import() at vendor\symfony\routing\Loader\YamlFileLoader.php:212
Symfony\Component\Routing\Loader\YamlFileLoader->parseImport() at vendor\symfony\routing\Loader\YamlFileLoader.php:99
Changing the definition to
#Route(path: '/foobar')
class FoobarController
{
}
or another name for the route fixes the error, but I want to use the FQCN as the route name.
How to reproduce
Create a controller like this:
// src/Controller/FoobarController.php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
#[Route('/foobar', self::class)]
class FoobarController
{
public function __invoke(): Response
{
return new Response('Hello World!');
}
}
Then execute a cache:warmup
.
Possible Solution
No response
Additional Context
No response