Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Route definitions incompatible with symfony/routing: 6.4.0 #52801

Closed
@fritzmg

Description

@fritzmg

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions