-
-
Notifications
You must be signed in to change notification settings - Fork 188
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
!!! FEATURE: WIP Dispatcher and controller return ActionResponse
(simpler controller pattern)
#3232
Conversation
WIP This change needs an accompanying adjustment to Neos to adjust the PluginImplementation as well as Modules. The new `SimpleActionController` gives you a direct and simple way to route an ActionRequest and return an ActionReponse with nothing in between. Routing should work just like with other ActionControllers. This is breaking if you implemented your own ControllerInterface or overwrote or expect some of the api methods of the ActionController. We now use a direct pattern of f(ActionRequest) => ActionResponse in more places. Adjusting existing controllers should be easy though. We discourage to manipulate `$this->reponse` in controllers, although it should still work fine in actions for now, please consider other options.
ac6f152
to
d94562f
Compare
13c3bb9
to
9cb9d3d
Compare
Probably still has a few rough edges but I would like to discuss this before putting more time into it. I made it so that for probably the 90% userland case nothing should change, but open options, the few people that did overwrite/mess around with the interface and methods I changed shoudl have an easy time adapting. we could go way further with this paying for it with more breakiness. |
Hi :D Thanks for this wip approach to have something concrete to discuss!. This new controller interface and the SimpleActionController look both real good. But i see that we have to go through some lengths to achieve this response manipulating "feature". Im not entirely sure if this is the best way to have a common interface for both legacy and new controllers. I think the code manipulation of the How about to keep our legacy controller code base as is and instead introduce a new interface? interface LegacyActionControllerInterface
{
public function processRequest(ActionRequest $request, ActionResponse $response): void;
} interface SimpleActionControllerInterface
{
public function processRequest(ActionRequest $request): ActionResponse;
} I also have been thinking about an controller which would work entirely only with psr requests and responses so that our users can apply their knowledge from other php frameworks and dont have to panic: /** implement your actions by the pattern {$name}Action, process the psr requet and return a response */
interface PsrControllerInterface
{
// @example
// public function indexAction(ServerRequest $request): Response;
} |
But then you have a lot of weird checks and contortions in the lower layers? As in the dispatcher and any other code (plugins, widgets etc.) need to suddenly deal with two ways to call a controller. IDK I find the readability not too bad actually. And now the weirdness happens at least only inside the ActionController. And then we can step by step reduce the surface of this weirdness down to only the action and declare that the response is only globally available during the action method call. Could even be something we can do right now, not sure how much of our core contorllers do something beyond that. Again PSR is a separate concern and not part of the dispatcher, that is a lower level we would have to build separate infrastructure for. |
I really like this approach. No property mapping and no mimetype negotiation to produce unexpected trouble \o/. @mhsdesign i think that this makes more sense with FlowActionRequest / Response as otherwise it would be more like a middleware. The middleware approach will probably be the path anyway $someone chooses if one does not want to learn a new framework. |
I think I do see a way in the future, we could move everything the ActionController does into the userland with services you can call. Like we deprecate regular actions at some point and say you just make it a SimpleController action and use the following services to get the same results (ala propertymapper -> validator -> view) and then the old code is just wrapped by a new simple controller action with a few lines of boilerplate to init the stuff. Future backwards compat controller way suggestion:
Total sketch code obviously but probably something we could rector... |
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.
I like that idea. I just would challange the name "SimpleActionController", but I have no better idea at the moment.
(Sorry for the typo change-requests at this point... I didn't expect that much and I was afraid it would be forgotten in the end)
Neos.FluidAdaptor/Tests/Unit/Core/Widget/AjaxWidgetMiddlewareTest.php
Outdated
Show resolved
Hide resolved
Neos.FluidAdaptor/Tests/Unit/Core/Widget/AjaxWidgetMiddlewareTest.php
Outdated
Show resolved
Hide resolved
9cb9d3d
to
8ee71e9
Compare
Note that if you want to test this with Neos you need to apply the patch for it as well |
Aaaand another unraveling, we do not really need Stop/ForwardActionException, we could just return.... For StopAction it's super easy, just return the (redirect/error/whatever) response. For ForwardAction something special is needed, it could stay an exception or we could attach the next request in some way to a response and just return that 🤔 |
Ha why does it always take time to fall into place :D I like this line of thought and that would reduce the api surface of the controller again. And the signature would change to
right? Wasnt that what basti suggested in: Additionally i did some small tweaking of things around: commit for commit is quite simple but it summs up to something, if you dont like that to go all in here we probably could split this up, but then again it feels nice to have all breaking notes on one pr? |
Also i just stumbled upon the EDIT: Followup #3295 |
I have this whole removal of dispatched sitting around here and now wonder if I shoulnd't rather make this a separate PR, I think this PR will become a huge mess fast and no one wants to review huge messes 🙈 |
Hmm i was actually thinking of branching 9.0 off to I think multiple prs is the way to go and we could possibly create depending prs where we agree to merge them not directly into this but wait first for this one to be merged. For that workflow it would be better if this pr was made from a neos branch and not on a fork ^^ so depending prs would reside here in neos... EDIT: As one cannot change the source of a pr, i created a temporary branch in neos |
Fyi this is my super small review pr kitsunet#4 (one commit) that should ideally go directly into this pr as the part have already been touched. Further adjustments to e.g. introduce trait instead of simple action controller: (comment #3232 (comment)) I would like to propose to revert the introduction of the |
Aaaand im also not so happy with some of the naming choices in Anything that is serious public api should deserve its own discussion and not be swallowed in a big change like this ... I would really like to get the basis of this change in rather quickly, as i prepared already some followups ^^ |
$packageKey .= '\\' . $subpackageKey; | ||
} | ||
$this->forward($request->getControllerActionName(), $request->getControllerName(), $packageKey, $request->getArguments()); | ||
$nextRequest = clone $request; |
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.
we only need to clone as far as i know, because that will unset the dispatch state? But that will be hopefully be fixed via #3301
I moved the simple controller over here and the special response stuff there After merging kitsunet#4 into here and deciding if #3294 should go in here or separate ( |
ActionResponse
(simpler controller pattern)
We discussed that we like the idea to return psr responses instead of an This PR will be merged into This will be done to also merge #3294 into that branch, and have one final place for last reviews. This PR with 76 comments escalated a bit, but after we stripped out the controversial parts into own prs most of the discussion that took place here is not related anymore to the core changes right now. |
ActionResponse
(simpler controller pattern)ActionResponse
(simpler controller pattern)
52cafdd
into
neos:feature/dispatcher-returns-psr-responses
will not be merged directly into 9.0 but included in this mvc overhaul pr: #3311
This change needs an accompanying adjustment to Neos to adjust the
PluginImplementation as well as Modules.
The newSimpleActionController
gives you a direct and simple way toroute an ActionRequest and return an ActionReponse with nothing in
between. Routing should work just like with other ActionControllers.
This is breaking if you implemented your own ControllerInterface
or overwrote or expect some of the api methods of the ActionController.
We now use a direct pattern of f(ActionRequest) => ActionResponse
in more places. Adjusting existing controllers should be easy though.
Additionally implementing your own dispatch loop (don't do this) will
need adjustments.
We discourage to manipulate
$this->reponse
in controllers,although it should still work fine in actions for now, please consider
other options.