From d279a9f683c64025d123f2252dbc4edbb14f0860 Mon Sep 17 00:00:00 2001 From: danadesrosiers Date: Fri, 28 Nov 2014 11:21:00 -0800 Subject: [PATCH] When registering a controller with a Controller annotation using the annot.controllers option, any prefix will be prepended to the prefix set by the Controller annotation. --- src/AnnotationService.php | 2 ++ test/AnnotationServiceProviderTest.php | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/AnnotationService.php b/src/AnnotationService.php index a498a5f..5f78ea9 100755 --- a/src/AnnotationService.php +++ b/src/AnnotationService.php @@ -154,6 +154,8 @@ public function registerController($controllerName, Controller $defaultControlle if (!($controllerAnnotation instanceof Controller)) { $controllerAnnotation = $defaultControllerAnnotation; + } else if ($defaultControllerAnnotation instanceof Controller) { + $controllerAnnotation->prefix = $defaultControllerAnnotation->prefix . $controllerAnnotation->prefix; } if ($controllerAnnotation instanceof Controller) { diff --git a/test/AnnotationServiceProviderTest.php b/test/AnnotationServiceProviderTest.php index 23ed208..e0d7c05 100755 --- a/test/AnnotationServiceProviderTest.php +++ b/test/AnnotationServiceProviderTest.php @@ -33,6 +33,18 @@ public function testRegisterControllersWithGroups() $this->assertEndPointStatus(self::GET_METHOD, '/group2/test2', self::STATUS_OK, $options); } + public function testGroupAndControllerPrefix() + { + $options = array( + "annot.controllers" => array( + 'group' => array("DDesrosiers\\Test\\SilexAnnotations\\Controller\\TestController") + ) + ); + + // both the annot.controller prefix and the Controller annotation prefix should be respected + $this->assertEndPointStatus(self::GET_METHOD, '/group/test/test1', self::STATUS_OK, $options); + } + public function testRegisterControllersByDirectoryProvider() { $subDirFqcn = self::CONTROLLER_NAMESPACE."SubDir\\SubDirTestController";