-
-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TASK: Introduce trait
ActionToMethodDelegation
instead of `SimpleAc…
…tionController`. 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.
- Loading branch information
Showing
5 changed files
with
72 additions
and
63 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
Neos.Flow/Classes/Mvc/Controller/ActionToMethodDelegation.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Neos\Flow\Mvc\Controller; | ||
|
||
use Neos\Flow\Mvc\ActionRequest; | ||
use Neos\Flow\Mvc\ActionResponse; | ||
use Neos\Flow\Mvc\Exception\NoSuchActionException; | ||
|
||
/** | ||
* Helps to implement a controller with direct access to flows request/response abstraction. | ||
* | ||
* ``` | ||
* ┌─────────────────────────────────────────────────────────────────────────────┐ | ||
* │ class MyController implements ControllerInterface │ | ||
* │ { │ | ||
* │ use ActionToMethodDelegation; │ | ||
* │ public function myAction(ActionRequest $actionRequest): ActionResponse; │ | ||
* │ } │ | ||
* └─────────────────────────────────────────────────────────────────────────────┘ | ||
* ``` | ||
* | ||
* The request comes directly from the dispatcher and goes directly back to it. | ||
* | ||
* For helpers to facilitate throws, forwards, redirects: {@see SpecialResponsesSupport} | ||
* | ||
* Views or other processing needs to be added to your controller as needed, | ||
* helpers will be suggested here as they become available. | ||
* @api | ||
*/ | ||
trait ActionToMethodDelegation | ||
{ | ||
/** | ||
* @internal you don't need to use this trait if you need to override this functionality. | ||
*/ | ||
final public function processRequest(ActionRequest $request): ActionResponse | ||
{ | ||
$request->setDispatched(true); | ||
$actionMethodName = $this->resolveActionMethodName($request); | ||
return $this->$actionMethodName($request); | ||
} | ||
|
||
/** | ||
* Resolves and checks the current action method name | ||
* | ||
* @return string Method name of the current action | ||
* @throws NoSuchActionException | ||
*/ | ||
private function resolveActionMethodName(ActionRequest $request): string | ||
{ | ||
$actionMethodName = $request->getControllerActionName() . 'Action'; | ||
if (!is_callable([$this, $actionMethodName])) { | ||
throw new NoSuchActionException(sprintf('An action "%s" does not exist in controller "%s".', $actionMethodName, get_class($this)), 1186669086); | ||
} | ||
|
||
return $actionMethodName; | ||
} | ||
} |
49 changes: 0 additions & 49 deletions
49
Neos.Flow/Classes/Mvc/Controller/SimpleActionController.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters