8000 bug #41782 [FrameworkBundle] fix removing "action" from route names (… · symfony/symfony@83825c5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 83825c5

Browse files
committed
bug #41782 [FrameworkBundle] fix removing "action" from route names (nicolas-grekas)
This PR was merged into the 5.4 branch. Discussion ---------- [FrameworkBundle] fix removing "action" from route names | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #40024 | License | MIT | Doc PR | - Commits ------- 7f4a84f [FrameworkBundle] fix removing "action" from route names
2 parents 76217fd + 7f4a84f commit 83825c5

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,12 @@ protected function configureRoute(Route $route, \ReflectionClass $class, \Reflec
4141
*/
4242
protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMethod $method)
4343
{
44-
return preg_replace([
45-
'/(bundle|controller)_/',
46-
'/action(_\d+)?$/',
47-
'/__/',
48-
], [
49-
'_',
50-
'\\1',
51-
'_',
52-
], parent::getDefaultRouteName($class, $method));
44+
$name = preg_replace('/(bundle|controller)_/', '_', parent::getDefaultRouteName($class, $method));
45+
46+
if (str_ends_with($method->name, 'Action') || str_ends_with($method->name, '_action')) {
47+
$name = preg_replace('/action(_\d+)?$/', '\\1', $name);
48+
}
49+
50+
return str_replace('__', '_', $name);
5351
}
5452
}

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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 8 additions & 0 deletions
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()
56+
{
57+
return new Response();
58+
}
5159
}

0 commit comments

Comments
 (0)
0