From 69e4b397ba0029c3e28339473bb45cd338f00c4a Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Thu, 21 Dec 2023 11:52:31 +0100 Subject: [PATCH] [DashboardBundle] Fix controller route attribute resolver in DashboardWidget --- .../DashboardBundle/Widget/DashboardWidget.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Kunstmaan/DashboardBundle/Widget/DashboardWidget.php b/src/Kunstmaan/DashboardBundle/Widget/DashboardWidget.php index 4ba94d02f5..e4e8fdadfb 100644 --- a/src/Kunstmaan/DashboardBundle/Widget/DashboardWidget.php +++ b/src/Kunstmaan/DashboardBundle/Widget/DashboardWidget.php @@ -28,6 +28,8 @@ public function resolvedController() { $annotationReader = new AnnotationReader(); $reflectionMethod = new \ReflectionMethod($this->controller, 'widgetAction'); + + // NEXT_MAJOR Remove annotation support $methodAnnotations = $annotationReader->getMethodAnnotations($reflectionMethod); foreach ($methodAnnotations as $annotation) { if ($annotation instanceof Route) { @@ -39,6 +41,16 @@ public function resolvedController() } } - throw new \Exception('There is no route annotation'); + $methodRouteAttributes = $reflectionMethod->getAttributes(Route::class, \ReflectionAttribute::IS_INSTANCEOF); + if ($methodRouteAttributes === []) { + throw new \Exception('There is no route annotation or attribute'); + } + + $attributeInstance = $methodRouteAttributes[0]->newInstance(); + if (null === $attributeInstance->getName()) { + throw new \Exception('The name is not configured in the attribute'); + } + + return $attributeInstance->getName(); } }