Skip to content

Commit

Permalink
Merge branch 'master' into query_param-proof-of-concept
Browse files Browse the repository at this point in the history
  • Loading branch information
lsmith77 committed Apr 19, 2012
2 parents ddcc3fa + ff4512e commit 3dc09ba
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ class UsersController extends Controller
{} // "patch_user" [PATCH] /users/{slug}

public function lockUserAction($slug)
{} // "lock_user" [POST] /users/{slug}/lock
{} // "lock_user" [PATCH] /users/{slug}/lock

public function banUserAction($slug, $id)
{} // "ban_user" [POST] /users/{slug}/ban
{} // "ban_user" [PATCH] /users/{slug}/ban

public function removeUserAction($slug)
{} // "remove_user" [GET] /users/{slug}/remove
Expand All @@ -94,8 +94,8 @@ class UsersController extends Controller
public function putUserCommentAction($slug, $id)
{} // "put_user_comment" [PUT] /users/{slug}/comments/{id}

public function voteUserCommentAction($slug, $id)
{} // "vote_user_comment" [POST] /users/{slug}/comments/{id}/vote
public function postUserCommentVoteAction($slug, $id)
{} // "post_user_comment_vote" [POST] /users/{slug}/comments/{id}/vote

public function removeUserCommentAction($slug, $id)
{} // "remove_user_comment" [GET] /users/{slug}/comments/{id}/remove
Expand Down Expand Up @@ -139,14 +139,14 @@ to *PUT*, or update, an existing resource. Shown as ``UsersController::editUserA
* **remove** - A hypermedia representation that acts as the engine to *DELETE*. Typically this is a form that allows the
client to *DELETE* an existing resource. Commonly a confirmation form. Shown as ``UsersController::removeUserAction()`` above.

### Custom POST Actions
### Custom PATCH Actions

All actions that do not match the ones listed in the sections above will register as a *POST* action. In the controller
All actions that do not match the ones listed in the sections above will register as a *PATCH* action. In the controller
shown above, these actions are ``UsersController::lockUserAction()``, ``UsersController::banUserAction()`` and
``UsersController::voteUserCommentAction()``. You could just as easily create a method called
``UsersController::promoteUserAction()`` which would take a *POST* request to the url */users/{slug}/promote*.
``UsersController::promoteUserAction()`` which would take a *PATCH* request to the url */users/{slug}/promote*.
This allows for easy updating of aspects of a resource, without having to deal with the resource as a whole at
the standard *POST* endpoint.
the standard *PATCH* or *PUT* endpoint.

### Sub-Resource Actions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ auto-generation process and can be any name you like.
<?php
class CommentsController extends Controller
{
public function voteCommentAction($slug, $id)
{} // "vote_user_comment" [POST] /users/{slug}/comments/{id}/vote
public function postCommentVoteAction($slug, $id)
{} // "post_user_comment_vote" [POST] /users/{slug}/comments/{id}/vote

public function getCommentsAction($slug)
{} // "get_user_comments" [GET] /users/{slug}/comments
Expand Down Expand Up @@ -118,7 +118,7 @@ RestBundle uses REST paths to generate route name. This means, that URL:
[POST] /users/{slug}/comments/{id}/vote
will become the route with the name ``vote_user_comment``.
will become the route with the name ``post_user_comment_vote``.
For further examples, see comments of controllers in the code above.
Expand Down
2 changes: 1 addition & 1 deletion Resources/doc/examples/RssHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function createResponse(ViewHandler $handler, View $view, Request $reques
$code = Codes::HTTP_OK;
} catch (\Exception $e) {
if ($this->logger) {
$this->logger->addError($e);
$this->logger->err($e);
}

$content = sprintf("%s:<br/><pre>%s</pre>", $e->getMessage(), $e->getTraceAsString());
Expand Down
2 changes: 1 addition & 1 deletion Routing/Loader/Reader/RestActionReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ private function getCustomHttpMethod($httpMethod, array $resources, array $argum
return 'get';
} else {
//custom object
return 'post';
return 'patch';
}
}

Expand Down
8 changes: 4 additions & 4 deletions Tests/Fixtures/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function patchUserAction($slug)
{} // [PATCH] /users/{slug}

public function lockUserAction($slug)
{} // [POST] /users/{slug}/lock
{} // [PATCH] /users/{slug}/lock

public function getUserCommentsAction($slug)
{} // [GET] /users/{slug}/comments
Expand All @@ -48,9 +48,9 @@ public function deleteUserCommentAction($slug, $id)
{} // [DELETE] /users/{slug}/comments/{id}

public function banUserAction($slug, $id)
{} // [POST] /users/{slug}/ban
{} // [PATCH] /users/{slug}/ban

public function voteUserCommentAction($slug, $id)
public function postUserCommentVoteAction($slug, $id)
{} // [POST] /users/{slug}/comments/{id}/vote

public function _userbarAction()
Expand Down Expand Up @@ -81,7 +81,7 @@ public function removeUserCommentAction($slug, $id)
{} // [GET] /users/{slug}/comments/{id}/remove

public function hideUserCommentAction($userId, $commentId)
{} // [POST] /users/{userId}/comments/{commentId}
{} // [PATCH] /users/{userId}/comments/{commentId}/hide

public function getFooBarsAction($foo)
{} // [GET] /foos/{foo}/bars
Expand Down
2 changes: 1 addition & 1 deletion Tests/Fixtures/Etalon/annotated_users_controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ rate_user:
rate_user_comment:
pattern: /users/{slug}/rate_comment/{id}.{_format}
controller: ::rateUserCommentAction
requirements: {_method: POST, slug: '[a-z]+', id: '\d+'}
requirements: {_method: PATCH, slug: '[a-z]+', id: '\d+'}

cget_user:
pattern: /users/{slug}/cget.{_format}
Expand Down
12 changes: 6 additions & 6 deletions Tests/Fixtures/Etalon/prefixed_users_collection.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ patch_user:
controller: ::patchUserAction

lock_user:
method: POST
method: PATCH
pattern: /resources/all/users/{slug}/lock.{_format}
controller: ::lockUserAction

Expand Down Expand Up @@ -59,14 +59,14 @@ new_user_comments:
controller: ::newUserCommentsAction

ban_user:
method: POST
method: PATCH
pattern: /resources/all/users/{slug}/ban.{_format}
controller: ::banUserAction

vote_user_comment:
post_user_comment_vote:
method: POST
pattern: /resources/all/users/{slug}/comments/{id}/vote.{_format}
controller: ::voteUserCommentAction
controller: ::postUserCommentVoteAction

get_user_topics:
method: GET
Expand All @@ -89,7 +89,7 @@ put_user_topic:
controller: ::putTopic

hide_user_topic:
method: POST
method: PATCH
pattern: /resources/all/users/{slug}/topics/{title}/hide.{_format}
controller: ::hideTopic

Expand All @@ -109,6 +109,6 @@ test_put_user_topic_comment:
controller: ::putComment

test_ban_user_topic_comment:
method: POST
method: PATCH
pattern: /resources/all/users/{slug}/topics/{title}/additional/comments/{id}/ban.{_format}
controller: ::banComment
12 changes: 6 additions & 6 deletions Tests/Fixtures/Etalon/users_collection.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ patch_user:
controller: ::patchUserAction

lock_user:
method: POST
method: PATCH
pattern: /users/{slug}/lock.{_format}
controller: ::lockUserAction

Expand Down Expand Up @@ -59,14 +59,14 @@ new_user_comments:
controller: ::newUserCommentsAction

ban_user:
method: POST
method: PATCH
pattern: /users/{slug}/ban.{_format}
controller: ::banUserAction

vote_user_comment:
post_user_comment_vote:
method: POST
pattern: /users/{slug}/comments/{id}/vote.{_format}
controller: ::voteUserCommentAction
controller: ::postUserCommentVoteAction

get_user_topics:
method: GET
Expand All @@ -89,7 +89,7 @@ put_user_topic:
controller: ::putTopic

hide_user_topic:
method: POST
method: PATCH
pattern: /users/{slug}/topics/{title}/hide.{_format}
controller: ::hideTopic

Expand All @@ -109,6 +109,6 @@ put_user_topic_comment:
controller: ::putComment

ban_user_topic_comment:
method: POST
method: PATCH
pattern: /users/{slug}/topics/{title}/comments/{id}/ban.{_format}
controller: ::banComment
10 changes: 5 additions & 5 deletions Tests/Fixtures/Etalon/users_controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ patch_user:
controller: ::patchUserAction

lock_user:
method: POST
method: PATCH
pattern: /users/{slug}/lock.{_format}
controller: ::lockUserAction

Expand Down Expand Up @@ -59,22 +59,22 @@ new_user_comments:
controller: ::newUserCommentsAction

ban_user:
method: POST
method: PATCH
pattern: /users/{slug}/ban.{_format}
controller: ::banUserAction

vote_user_comment:
post_user_comment_vote:
method: POST
pattern: /users/{slug}/comments/{id}/vote.{_format}
controller: ::voteUserCommentAction
controller: ::postUserCommentVoteAction

check_username_users:
method: GET
pattern: /users/check_username.{_format}
controller: ::check_usernameUsersAction

hide_user_comment:
method: POST
method: PATCH
pattern: /users/{userId}/comments/{commentId}/hide.{_format}
controller: ::hideUserCommentAction

Expand Down
2 changes: 1 addition & 1 deletion Tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

$file = __DIR__.'/../vendor/.composer/autoload.php';
$file = __DIR__.'/../vendor/autoload.php';
if (!file_exists($file)) {
throw new RuntimeException('Install dependencies to run test suite.');
}
Expand Down
8 changes: 8 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ list important BC breaks.
* moved serializer configuration code from ViewHandler::createResponse() to ViewHandler::getSerializer()
* made ViewHandler::getSerializer() protected again

### 19 April 2012

* Change route fallback action to PATCH instead of POST

Automatically generated routes will now fall back to the PATCH instead of the POST method.

More information in the docs, at [this issue](https://github.com/FriendsOfSymfony/FOSRestBundle/issues/223) and [this PR](https://github.com/FriendsOfSymfony/FOSRestBundle/pull/224).

### upgrading from 0.5.0_old_serializer

* The ViewInterface is gone so you might have to change your controller config if you refer to the fos_rest.view service.
Expand Down

0 comments on commit 3dc09ba

Please sign in to comment.