Skip to content

Commit a26be0c

Browse files
committed
Merge pull request #879 from Zeichen32/fix-878
Annotation: Routing name is just appending to generic route name
2 parents 350743c + dfdd274 commit a26be0c

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

Routing/Loader/Reader/RestActionReader.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,14 @@ private function readMethodAnnotations(\ReflectionMethod $reflectionMethod, $ann
535535
*/
536536
private function addRoute(RestRouteCollection $collection, $routeName, $route, $isCollection, $isInflectable, RouteAnnotation $annotation = null)
537537
{
538-
if ($annotation) {
539-
$routeName = $routeName.$annotation->getName();
538+
if ($annotation && null !== $annotation->getName()) {
539+
$options = $annotation->getOptions();
540+
541+
if(isset($options['method_prefix']) && false === $options['method_prefix']) {
542+
$routeName = $annotation->getName();
543+
} else {
544+
$routeName = $routeName.$annotation->getName();
545+
}
540546
}
541547

542548
$fullRouteName = $this->namePrefix.$routeName;

Tests/Fixtures/Controller/AnnotatedUsersController.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,12 @@ public function customUserAction($slug)
139139
*/
140140
public function multiplegetUsersAction()
141141
{}
142+
143+
/**
144+
* @POST("/users1/{foo}", name="post_users_foo", options={ "method_prefix" = false })
145+
* @POST("/users2/{foo}", name="post_users_bar", options={ "method_prefix" = false })
146+
*
147+
*/
148+
public function multiplepostUsersAction()
149+
{}
142150
}

Tests/Fixtures/Etalon/annotated_users_controller.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,12 @@ multipleget_users_a_link_method:
7575
pattern: /users1.{_format}
7676
controller: ::multiplegetUsersAction
7777
requirements: {_method: LINK}
78+
79+
post_users_foo:
80+
pattern: /users1/{foo}.{_format}
81+
controller: ::multiplepostUsersAction
82+
requirements: {_method: POST}
83+
post_users_bar:
84+
pattern: /users2/{foo}.{_format}
85+
controller: ::multiplepostUsersAction
86+
requirements: {_method: POST}

Tests/Routing/Loader/RestRouteLoaderTest.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function testAnnotatedUsersFixture()
9494
$etalonRoutes = $this->loadEtalonRoutesInfo('annotated_users_controller.yml');
9595

9696
$this->assertTrue($collection instanceof RestRouteCollection);
97-
$this->assertEquals(21, count($collection->all()));
97+
$this->assertEquals(23, count($collection->all()));
9898

9999
foreach ($etalonRoutes as $name => $params) {
100100
$route = $collection->get($name);
@@ -279,6 +279,17 @@ public function testNamePrefixIsPrependingCorrectly()
279279
$this->assertNotNull($collection->get('prefix_cget_information'));
280280
}
281281

282+
/**
283+
* @see https://github.com/FriendsOfSymfony/FOSRestBundle/pull/879
284+
*/
285+
public function testNameMethodPrefixIsPrependingCorrectly()
286+
{
287+
$collection = $this->loadFromControllerFixture('AnnotatedUsersController');
288+
289+
$this->assertNotNull($collection->get('post_users_foo'), 'route for "post_users_foo" does not exist');
290+
$this->assertNotNull($collection->get('post_users_bar'), 'route for "post_users_bar" does not exist');
291+
}
292+
282293
/**
283294
* Load routes collection from fixture class under Tests\Fixtures directory.
284295
*

0 commit comments

Comments
 (0)