Skip to content

Commit 98f82fe

Browse files
[FrameworkBundle] fix removing "action" from route names
1 parent 63e4269 commit 98f82fe

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

src/Symfony/Bundle/FrameworkBundle/Routing/AnnotatedRouteControllerLoader.php

+7-9
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,12 @@ protected function configureRoute(Route $route, \ReflectionClass $class, \Reflec
4343
*/
4444
protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMethod $method)
4545
{
46-
return preg_replace([
47-
'/(bundle|controller)_/',
48-
'/action(_\d+)?$/',
49-
'/__/',
50-
], [
51-
'_',
52-
'\\1',
53-
'_',
54-
], parent::getDefaultRouteName($class, $method));
46+
$name = preg_replace('/(bundle|controller)_/', '_', parent::getDefaultRouteName($class, $method));
47+
48+
if ('Action' === substr($method->name, -6) || '_action' === substr($method->name, -7)) {
49+
$name = preg_replace('/action(_\d+)?$/', '\\1', $name);
50+
}
51+
52+
return str_replace('__', '_', $name);
5553
}
5654
}

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AnnotatedControllerTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ public function testAnnotatedController($path, $expectedValue)
2323

2424
$this->assertSame(200, $client->getResponse()->getStatusCode());
2525
$this->assertSame($expectedValue, $client->getResponse()->getContent());
26+
27+
$router = self::$container->get('router');
28+
29+
$this->assertSame('/annotated/create-transaction', $router->generate('symfony_framework_tests_functional_test_annotated_createtransaction'));
2630
}
2731

2832
public function getRoutes()

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/AnnotatedController.php

+8
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,12 @@ public function argumentWithoutDefaultWithRouteParamAndDefaultAction($value)
4848
{
4949
return new Response($value);
5050
}
51+
52+
/**
53+
* @Route("/create-transaction")
54+
*/
55+
public function createTransaction($value)
56+
{
57+
return new Response($value);
58+
}
5159
}

0 commit comments

Comments
 (0)