Skip to content

Commit 24f2776

Browse files
committed
Merge pull request #1351 from xabbuh/backport-1314
backport RFC-2518 annotations
2 parents 913a0ee + bed7bbc commit 24f2776

File tree

16 files changed

+423
-30
lines changed

16 files changed

+423
-30
lines changed

Controller/Annotations/Copy.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSRestBundle package.
5+
*
6+
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace FOS\RestBundle\Controller\Annotations;
13+
14+
/**
15+
* COPY Route annotation class.
16+
*
17+
* @Annotation
18+
* @Target("METHOD")
19+
*
20+
* @author Maximilian Bosch <[email protected]>
21+
*/
22+
class Copy extends Route
23+
{
24+
public function getMethod()
25+
{
26+
return 'COPY';
27+
}
28+
}

Controller/Annotations/Lock.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSRestBundle package.
5+
*
6+
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace FOS\RestBundle\Controller\Annotations;
13+
14+
/**
15+
* LOCK Route annotation class.
16+
*
17+
* @Annotation
18+
* @Target("METHOD")
19+
*
20+
* @author Maximilian Bosch <[email protected]>
21+
*/
22+
class Lock extends Route
23+
{
24+
public function getMethod()
25+
{
26+
return 'LOCK';
27+
}
28+
}

Controller/Annotations/Mkcol.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSRestBundle package.
5+
*
6+
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace FOS\RestBundle\Controller\Annotations;
13+
14+
/**
15+
* MKCOL Route annotation class.
16+
*
17+
* @Annotation
18+
* @Target("METHOD")
19+
*
20+
* @author Maximilian Bosch <[email protected]>
21+
*/
22+
class Mkcol extends Route
23+
{
24+
public function getMethod()
25+
{
26+
return 'MKCOL';
27+
}
28+
}

Controller/Annotations/Move.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSRestBundle package.
5+
*
6+
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace FOS\RestBundle\Controller\Annotations;
13+
14+
/**
15+
* MOVE Route annotation class.
16+
*
17+
* @Annotation
18+
* @Target("METHOD")
19+
*
20+
* @author Maximilian Bosch <[email protected]>
21+
*/
22+
class Move extends Route
23+
{
24+
public function getMethod()
25+
{
26+
return 'MOVE';
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSRestBundle package.
5+
*
6+
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace FOS\RestBundle\Controller\Annotations;
13+
14+
/**
15+
* PROPFIND Route annotation class.
16+
*
17+
* @Annotation
18+
* @Target("METHOD")
19+
*
20+
* @author Maximilian Bosch <[email protected]>
21+
*/
22+
class PropFind extends Route
23+
{
24+
public function getMethod()
25+
{
26+
return 'PROPFIND';
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSRestBundle package.
5+
*
6+
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace FOS\RestBundle\Controller\Annotations;
13+
14+
/**
15+
* PROPPATCH Route annotation class.
16+
*
17+
* @Annotation
18+
* @Target("METHOD")
19+
*
20+
* @author Maximilian Bosch <[email protected]>
21+
*/
22+
class PropPatch extends Route
23+
{
24+
public function getMethod()
25+
{
26+
return 'PROPPATCH';
27+
}
28+
}

Controller/Annotations/Unlock.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSRestBundle package.
5+
*
6+
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace FOS\RestBundle\Controller\Annotations;
13+
14+
/**
15+
* UNLOCK Route annotation class.
16+
*
17+
* @Annotation
18+
* @Target("METHOD")
19+
*
20+
* @author Maximilian Bosch <[email protected]>
21+
*/
22+
class Unlock extends Route
23+
{
24+
public function getMethod()
25+
{
26+
return 'UNLOCK';
27+
}
28+
}

Resources/doc/5-automatic-route-generation_single-restful-controller.rst

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,44 +45,62 @@ Define resource actions
4545
<?php
4646
class UsersController
4747
{
48+
public function copyUserAction($id) // RFC-2518
49+
{} // "copy_user" [PATCH] /users/{id}/copy
50+
51+
public function propfindUserPropsAction($id, $property) // RFC-2518
52+
{} // "propfind_user_props" [PATCH] /users/{id}/props/{property}/propfind
53+
54+
public function proppatchUserPropsAction($id, $property) // RFC-2518
55+
{} // "proppatch_user_props" [PATCH] /users/{id}/props/{property}/proppatch
56+
57+
public function moveUserAction($id) // RFC-2518
58+
{} // "move_user" [PATCH] /users/{id}/move
59+
60+
public function mkcolUsersAction() // RFC-2518
61+
{} // "mkcol_users" [GET] /users/mkcol
62+
4863
public function optionsUsersAction()
49-
{} // "options_users" [OPTIONS] /users
64+
{} // "options_users" [OPTIONS] /users
5065
5166
public function getUsersAction()
52-
{} // "get_users" [GET] /users
67+
{} // "get_users" [GET] /users
5368
5469
public function newUsersAction()
55-
{} // "new_users" [GET] /users/new
70+
{} // "new_users" [GET] /users/new
5671
5772
public function postUsersAction()
58-
{} // "post_users" [POST] /users
73+
{} // "post_users" [POST] /users
5974
6075
public function patchUsersAction()
61-
{} // "patch_users" [PATCH] /users
76+
{} // "patch_users" [PATCH] /users
6277
6378
public function getUserAction($slug)
64-
{} // "get_user" [GET] /users/{slug}
79+
{} // "get_user" [GET] /users/{slug}
6580
6681
public function editUserAction($slug)
67-
{} // "edit_user" [GET] /users/{slug}/edit
82+
{} // "edit_user" [GET] /users/{slug}/edit
6883
6984
public function putUserAction($slug)
70-
{} // "put_user" [PUT] /users/{slug}
85+
{} // "put_user" [PUT] /users/{slug}
7186
7287
public function patchUserAction($slug)
73-
{} // "patch_user" [PATCH] /users/{slug}
88+
{} // "patch_user" [PATCH] /users/{slug}
7489
7590
public function lockUserAction($slug)
76-
{} // "lock_user" [PATCH] /users/{slug}/lock
91+
{} // "lock_user" [PATCH] /users/{slug}/lock
92+
93+
public function unlockUserAction($slug)
94+
{} // "unlock_user" [PATCH] /users/{slug}/unlock
7795
7896
public function banUserAction($slug)
79-
{} // "ban_user" [PATCH] /users/{slug}/ban
97+
{} // "ban_user" [PATCH] /users/{slug}/ban
8098
8199
public function removeUserAction($slug)
82-
{} // "remove_user" [GET] /users/{slug}/remove
100+
{} // "remove_user" [GET] /users/{slug}/remove
83101
84102
public function deleteUserAction($slug)
85-
{} // "delete_user" [DELETE] /users/{slug}
103+
{} // "delete_user" [DELETE] /users/{slug}
86104
87105
public function getUserCommentsAction($slug)
88106
{} // "get_user_comments" [GET] /users/{slug}/comments

Resources/doc/annotations-reference.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Route
9292

9393
RestBundle extends the `@Route Symfony annotation`_ from Symfony.
9494

95-
@Delete @Get @Head @Link @Patch @Post @Put @Unlink have the same options as @Route.
95+
@Delete @Get @Head @Link @Patch @Post @Put @Unlink @Lock @Unlock @PropFind @PropPatch @Move @Mkcol @Copy have the same options as @Route.
9696

9797
When using ``symfony/routing:>=2.4`` (or the full framework) you have access to
9898
the expression language component and can add conditions to your routing

Routing/Loader/Reader/RestActionReader.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
namespace FOS\RestBundle\Routing\Loader\Reader;
1313

1414
use Doctrine\Common\Annotations\Reader;
15-
use Symfony\Component\Routing\Route;
1615
use FOS\RestBundle\Controller\Annotations\Route as RouteAnnotation;
17-
use FOS\RestBundle\Util\Inflector\InflectorInterface;
16+
use FOS\RestBundle\Inflector\InflectorInterface;
1817
use FOS\RestBundle\Routing\RestRouteCollection;
1918
use FOS\RestBundle\Request\ParamReader;
19+
use Symfony\Component\Routing\Route;
2020

2121
/**
2222
* REST controller actions reader.
@@ -203,6 +203,14 @@ public function read(RestRouteCollection $collection, \ReflectionMethod $method,
203203

204204
if (!empty($annoMethods)) {
205205
$methods = $annoMethods;
206+
207+
// workaround for new method annotations that are not supported in method
208+
// names until FOSRestBundle 2.0 for BC reasons (if this check wasn't added
209+
// the method name would have been appended to the generated path)
210+
if (!in_array(strtolower($annotation->getMethod()), $this->availableHTTPMethods)) {
211+
array_pop($urlParts);
212+
$path = implode('/', $urlParts);
213+
}
206214
}
207215

208216
$path = $annotation->getPath() !== null ? $this->routePrefix.$annotation->getPath() : $path;

0 commit comments

Comments
 (0)