New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added ability to determine route "resources" from the Controller #269
Conversation
…Controller rather than the method name still needs some tests, documentation and review
@@ -116,7 +116,7 @@ public function getParents() | |||
* | |||
* @return Route | |||
*/ | |||
public function read(RestRouteCollection $collection, \ReflectionMethod $method) | |||
public function read(RestRouteCollection $collection, \ReflectionMethod $method, $resource = 'rest') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value looks weird here. Shouldn't it be an empty string (or null) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why? 'rest' is the default/current behavior
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is the default for the type. but this is not what the RestActionReader receives. It receives a resource (this does not affect your example as the default value is not really used anyway: the RestControllerReader always pass it explicitly as an empty string for the new behavior).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah .. i see what you mean now .. yup that code messed up during refactoring. will have a look
isn't it a BC break ? From what I see, the current behavior is achieved by using |
nvm, I misunderstood the behavior before looking at the example |
@lsmith77 could you give me some reasoning behind this, cuz i'm totally lost (but still interested in understanding) :) |
@everzet Allowing to omit the resource name from the methods, thus allowing to implement these methods using traits (or using a base class) for different controllers. |
Apart from these two questions +1 from me. Having |
@everzet what @stof said .. this way you can also have a generic base class if you are not yet on 5.4. for subresources our concept was to require separate controllers. ie. UserController for /users, UserTopicController for /users/topics etc. @asm89 I discussed this option with @beberlei but we didnt want to force the use of annotations. that being said, i think i now know a bit more about routing and will make another attempt at trying to add a new parameter to the routes to be able configure this new behavior. |
Several reasons from my side:
|
…esource name we need to implement a separate metadata format for yml/xml to cover all the route related annotations anyway
… resource via an annotation
…o leave out (parts) of the resource name in the method
this will for example detect cases of getAction() vs getArticleAction() inside a controller named ArticleController
My take on the issue is injecting "User" or "Users" depending on the amount of parameters on the method, but always doing this for all the methods in the class. Code! Mind it is in PoC state. So hardcoded class with resource and adjusted the original test.
Minus:
What is still an issue though is how to map the following:
These methods can't co-exist in the same class in php. A more explicit solution might be adding a 'collection' prefix to the predefined keywords? For example
|
@asm89 i have done some refactoring to radically simplify the code base. i am fairly happy with things now .. except for the logic for how to determine if to pluralize or not inside Right now I am using "List" as well as the conventional http methods to trigger the pluralization. Switching to instead prefixing the http method with "c" seems less intuitive. Also I am not sure about the special rule for conventional http methods. Right now one needs to write |
ok .. i decided i didnt like "List" as a special resource, since its not a standard term in the REST world. switching to "Collection" seemed better .. but that seemed a bit long and stuff like "postCollectionAction" still sounded stupid. as @asm89 pointed out we already have special handling for the http methods, so it makes more sense to do such stuff there as well. for now i went with the "c" prefix. |
…te names now do not have pluralized resources)
For what it's worth, I have adjusted my "fork" of this PR (which was not behaving the same as the implementation of @lsmith77 before) to also include the @lsmith77 I have a separate commit with the tests that you can cherry-pick if you want: asm89/FOSRestBundle@798d5a2. |
@asm89 can you summarize the behavior or implementation advantages of your approach? |
I don't think it differs much from your code anymore since we gradually worked to the point where we do the same. :)
In the implementation I didn't change any existing tests (no BC breaks?), I only added new tests to verify the new behaviour (you can cherry-pick them :) asm89/FOSRestBundle@798d5a2). |
ok .. i cherry picked your tests and made them work with my implementation. so from my POV the main thing missing now is docs .. for now see the tests and the LiipHelloBundle example one area where i am still a bit unsure if it should be possible to configure sub resources via the controller name because we already support this via the "parent" .. then again if i want to split up my controller into a UserController and a UserCommentController .. i might also want to have a CommentController .. so leaving out the parent resource from the controller name could lead to collisions. so i think its fine the way it is. @everzet can you have a look? |
👍 Let's see what @everzet has to say about it. |
it seems nice, https://groups.google.com/forum/?fromgroups#!topic/symfony2/7uKWq9OX6S0%5B1-25%5D |
ping @everzet |
added ability to determine route "resources" from the Controller
oops .. didnt realize the PR didnt include docs .. any volunteers? |
How to create a POST route with this patch? I've created a function named postRegisterAction() in my UsersController, |
@pierrre if you don't like the generated pattern, you can always change it by adding the |
still needs some tests (especially with subresources), documentation and review
please also see https://github.com/liip/LiipHelloBundle/compare/rest_class for an example
@everzet @beberlei