Skip to content

Commit

Permalink
bug #6692 Fix AdminRouteGenerator assuming the Route attribute is use…
Browse files Browse the repository at this point in the history
…d from the Attribute namespace instead of the Annotation's (systemasis)

This PR was squashed before being merged into the 4.x branch.

Discussion
----------

Fix AdminRouteGenerator assuming the Route attribute is used from the Attribute namespace instead of the Annotation's

Fixes #6687

Commits
-------

691b2c6 Fix AdminRouteGenerator assuming the Route attribute is used from the Attribute namespace instead of the Annotation's
  • Loading branch information
javiereguiluz committed Jan 7, 2025
2 parents 2dfefea + 691b2c6 commit f09fbd3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/Router/AdminRouteGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,14 @@ private function getDashboardsRouteConfig(): array
foreach ($this->dashboardControllers as $dashboardController) {
$reflectionClass = new \ReflectionClass($dashboardController);
$indexMethod = $reflectionClass->getMethod('index');
$routeAttributeFqcn = class_exists(\Symfony\Component\Routing\Attribute\Route::class) ? \Symfony\Component\Routing\Attribute\Route::class : \Symfony\Component\Routing\Annotation\Route::class;
$attributes = $indexMethod->getAttributes($routeAttributeFqcn);

if (class_exists(\Symfony\Component\Routing\Attribute\Route::class)) {
$attributes = $indexMethod->getAttributes(\Symfony\Component\Routing\Attribute\Route::class);
}

if (!isset($attributes) || [] === $attributes) {
$attributes = $indexMethod->getAttributes(\Symfony\Component\Routing\Annotation\Route::class);
}

if ([] === $attributes) {
throw new \RuntimeException(sprintf('When using pretty URLs, the "%s" EasyAdmin dashboard controller must define its route configuration (route name and path) using Symfony\'s #[Route] attribute applied to its "index()" method.', $reflectionClass->getName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use EasyCorp\Bundle\EasyAdminBundle\Tests\PrettyUrlsTestApplication\Entity\BlogPost;
use EasyCorp\Bundle\EasyAdminBundle\Tests\PrettyUrlsTestApplication\Entity\Category;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Routing\Annotation\Route;

class DashboardController extends AbstractDashboardController
{
Expand Down

0 comments on commit f09fbd3

Please sign in to comment.