From 691b2c6e62432967db92be59bf3c16a3848a61e1 Mon Sep 17 00:00:00 2001 From: systemasis Date: Tue, 7 Jan 2025 13:53:01 +0100 Subject: [PATCH] Fix AdminRouteGenerator assuming the Route attribute is used from the Attribute namespace instead of the Annotation's --- src/Router/AdminRouteGenerator.php | 10 ++++++++-- .../src/Controller/DashboardController.php | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Router/AdminRouteGenerator.php b/src/Router/AdminRouteGenerator.php index 9c5eb7d9ac..c62b72a502 100644 --- a/src/Router/AdminRouteGenerator.php +++ b/src/Router/AdminRouteGenerator.php @@ -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())); diff --git a/tests/PrettyUrlsTestApplication/src/Controller/DashboardController.php b/tests/PrettyUrlsTestApplication/src/Controller/DashboardController.php index 6e00e5b272..dface666a4 100644 --- a/tests/PrettyUrlsTestApplication/src/Controller/DashboardController.php +++ b/tests/PrettyUrlsTestApplication/src/Controller/DashboardController.php @@ -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 {