flow-development-collection
flow-development-collection copied to clipboard
EXPERIMENT: FEATURE: Introduce trait `ActionToMethodDelegation` to create own simple controller.
The name of the previously suggested SimpleActionController looked for improvement.
The Simple* prefix suggest, that the initial implementation blew up too much. But ideally a name would be more obvious and not suggest that there is another complex action controller.
I could not come up with a better name, but we can make the controllers more composable.
This change introduces a trait which implements the logic of the previous SimpleActionController.
That way people can implement the ControllerInterface directly and use a trait that will map action to method name.
class SimpleActionTestController implements ControllerInterface
{
use ActionToMethodDelegation;
public function addTestContentAction(ActionRequest $actionRequest): ActionResponse
{
$response = new ActionResponse();
$response->setContent('Simple');
return $response;
}
}
Upgrade instructions
Review instructions
See also
- https://github.com/neos/flow-development-collection/pull/3232#discussion_r1466751316
Checklist
- [ ] Code follows the PSR-2 coding style
- [ ] Tests have been created, run and adjusted as needed
- [ ] The PR is created against the lowest maintained branch
- [ ] Reviewer - PR Title is brief but complete and starts with
FEATURE|TASK|BUGFIX - [ ] Reviewer - The first section explains the change briefly for change-logs
- [ ] Reviewer - Breaking Changes are marked with
!!!and have upgrade-instructions
Haha, well, I wanted to do this after I finish my work stuff, well, good good. Btw, this ignores the public method thing you noted on the original simple controller chnage before, and I wanted to comment that that needs reflection which is nasty, so I would rather not check visibility.
I was unsure to do this in this pr or let this trait first be destroyed by someone who dislikes it :D
Actually i did plan on using reflection as its super fast nowadays (faster than property mapping :D)
https://stackoverflow.com/questions/4160901/how-to-check-if-a-function-is-public-or-protected-in-php
Is Callable way: 0.0033209323883057ms
Reflection way: 0.0052220821380615ms
Aaand i really think that we should keep this change out of the main pr https://github.com/neos/flow-development-collection/pull/3232#issuecomment-1916592740 right now (also the class SimpleActionController) as this might otherwise get 90% of the discussion focus and the rest of that big pr is lost.
The introduction of process(): Response might be enough ^^ for one pr ^^
I was unsure to do this in this pr or let this trait first be destroyed by someone who dislikes it :D
Actually i did plan on using reflection as its super fast nowadays (faster than property mapping :D)
https://stackoverflow.com/questions/4160901/how-to-check-if-a-function-is-public-or-protected-in-php
Neat, well then, great, we can check callable and public in one go.
We should/could use this also for the existing Controller?!
We should/could use this also for the existing Controller?!
Yes sounds great. And im already glad this is an own pr 😅
We also discussed to keep the *Action pattern or not: https://github.com/neos/flow-development-collection/pull/3232#discussion_r1466758693 but it seems its here to stay :)
do we want to keep the
*Actionpattern, because it still happens to me that i miss the suffix and it takes some time to figure out again what i missed 😅 , to fix this we could just improve therouting:matchcommand or the like to emit a warning, or wait we cannot as this is highly dynamic and we have to have an actual request at hand.
Mmm, yeah I thought about changing it, and I wouldn't mind that, for me I would actually say just make it an attribute? just allowing any method (without marker like an attribute) seems dangerous-ish especially if someone doesn't do proper sec policies. Also this then wouldn't match any existing policies as they all assume Action, so I just kept it that way.