diff --git a/src/Symfony/Bundle/FrameworkBundle/Routing/AnnotatedRouteControllerLoader.php b/src/Symfony/Bundle/FrameworkBundle/Routing/AnnotatedRouteControllerLoader.php index e708b70ca712e..511e87058b802 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Routing/AnnotatedRouteControllerLoader.php +++ b/src/Symfony/Bundle/FrameworkBundle/Routing/AnnotatedRouteControllerLoader.php @@ -41,14 +41,12 @@ protected function configureRoute(Route $route, \ReflectionClass $class, \Reflec */ protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMethod $method) { - return preg_replace([ - '/(bundle|controller)_/', - '/action(_\d+)?$/', - '/__/', - ], [ - '_', - '\\1', - '_', - ], parent::getDefaultRouteName($class, $method)); + $name = preg_replace('/(bundle|controller)_/', '_', parent::getDefaultRouteName($class, $method)); + + if (str_ends_with($method->name, 'Action') || str_ends_with($method->name, '_action')) { + $name = preg_replace('/action(_\d+)?$/', '\\1', $name); + } + + return str_replace('__', '_', $name); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AnnotatedControllerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AnnotatedControllerTest.php index c9ede7a9cf646..20d3609c16a84 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AnnotatedControllerTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AnnotatedControllerTest.php @@ -23,6 +23,10 @@ public function testAnnotatedController($path, $expectedValue) $this->assertSame(200, $client->getResponse()->getStatusCode()); $this->assertSame($expectedValue, $client->getResponse()->getContent()); + + $router = self::$container->get('router'); + + $this->assertSame('/annotated/create-transaction', $router->generate('symfony_framework_tests_functional_test_annotated_createtransaction')); } public function getRoutes() diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/AnnotatedController.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/AnnotatedController.php index 96543ce10f6b4..f2f077786f2b7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/AnnotatedController.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/AnnotatedController.php @@ -48,4 +48,12 @@ public function argumentWithoutDefaultWithRouteParamAndDefaultAction($value) { return new Response($value); } + + /** + * @Route("/create-transaction") + */ + public function createTransaction() + { + return new Response(); + } }