Skip to content

Commit

Permalink
Fix AdminRouteGenerator assuming the Route attribute is used from the…
Browse files Browse the repository at this point in the history
… Attribute namespace instead of the Annotation's
  • Loading branch information
systemasis authored and javiereguiluz committed Jan 7, 2025
1 parent 0553f47 commit 691b2c6
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 691b2c6

Please sign in to comment.