Skip to content

Commit ee5b089

Browse files
author
Jens Averkamp
committed
Add method_prefix annotation option
1 parent cb2895d commit ee5b089

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

Routing/Loader/Reader/RestActionReader.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,8 @@ private function readMethodAnnotations(\ReflectionMethod $reflectionMethod, $ann
536536
private function addRoute(RestRouteCollection $collection, $routeName, $route, $isCollection, $isInflectable, RouteAnnotation $annotation = null)
537537
{
538538
if ($annotation && null !== $annotation->getName()) {
539-
$routeName = $annotation->getName();
539+
$options = $annotation->getOptions();
540+
$routeName = empty($options['method_prefix']) ? $annotation->getName() : $routeName.$annotation->getName();
540541
}
541542

542543
$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="_foo", options={"method_prefix" = true })
145+
* @POST("/users2/{foo}", name="_bar", options={"method_prefix" = true })
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+
multiplepost_users_foo:
80+
pattern: /users1/{foo}.{_format}
81+
controller: ::multiplepostUsersAction
82+
requirements: {_method: POST}
83+
multiplepost_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('multiplepost_users_foo'));
290+
$this->assertNotNull($collection->get('multiplepost_users_bar'));
291+
}
292+
282293
/**
283294
* Load routes collection from fixture class under Tests\Fixtures directory.
284295
*

0 commit comments

Comments
 (0)