forked from neos/flow-development-collection
-
Notifications
You must be signed in to change notification settings - Fork 1
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
TASK: Avoid accessing "global" request, response and arguments in action controller #4
Closed
mhsdesign
wants to merge
1
commit into
kitsunet:feature/actioncontroller-simplecontroller
from
mhsdesign:task/actioncontroller-simplecontroller-review-2
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -222,9 +222,9 @@ public function processRequest(ActionRequest $request): ActionResponse | |
|
||
$this->actionMethodName = $this->resolveActionMethodName($request); | ||
|
||
$this->initializeActionMethodArguments(); | ||
$this->initializeActionMethodArguments($this->arguments); | ||
if ($this->enableDynamicTypeValidation !== true) { | ||
$this->initializeActionMethodValidators(); | ||
$this->initializeActionMethodValidators($this->arguments); | ||
} | ||
|
||
$this->initializeAction(); | ||
|
@@ -241,14 +241,14 @@ public function processRequest(ActionRequest $request): ActionResponse | |
} | ||
|
||
try { | ||
$this->mapRequestArgumentsToControllerArguments($request); | ||
$this->mapRequestArgumentsToControllerArguments($request, $this->arguments); | ||
} catch (RequiredArgumentMissingException $e) { | ||
$message = $this->throwableStorage->logThrowable($e); | ||
$this->logger->notice('Request argument mapping failed due to a missing required argument. ' . $message, LogEnvironment::fromMethodName(__METHOD__)); | ||
$this->throwStatus(400, null, 'Required argument is missing'); | ||
} | ||
if ($this->enableDynamicTypeValidation === true) { | ||
$this->initializeActionMethodValidators(); | ||
$this->initializeActionMethodValidators($this->arguments); | ||
} | ||
|
||
if ($this->view === null) { | ||
|
@@ -260,8 +260,7 @@ public function processRequest(ActionRequest $request): ActionResponse | |
$this->initializeView($this->view); | ||
} | ||
|
||
// We still use a global response here as it might have been changed in any of the steps above | ||
$response = $this->callActionMethod($request, $this->response); | ||
$response = $this->callActionMethod($request, $this->arguments, $response); | ||
|
||
if (!$response->hasContentType()) { | ||
$response->setContentType($this->negotiatedMediaType); | ||
|
@@ -301,7 +300,7 @@ protected function resolveActionMethodName(ActionRequest $request): string | |
* @throws InvalidArgumentTypeException | ||
* @see initializeArguments() | ||
*/ | ||
protected function initializeActionMethodArguments() | ||
protected function initializeActionMethodArguments(Arguments $arguments) | ||
{ | ||
$actionMethodParameters = static::getActionMethodParameters($this->objectManager); | ||
if (isset($actionMethodParameters[$this->actionMethodName])) { | ||
|
@@ -310,7 +309,7 @@ protected function initializeActionMethodArguments() | |
$methodParameters = []; | ||
} | ||
|
||
$this->arguments->removeAll(); | ||
$arguments->removeAll(); | ||
foreach ($methodParameters as $parameterName => $parameterInfo) { | ||
$dataType = null; | ||
if (isset($parameterInfo['type'])) { | ||
|
@@ -326,7 +325,7 @@ protected function initializeActionMethodArguments() | |
$dataType = TypeHandling::stripNullableType($dataType); | ||
} | ||
$mapRequestBody = isset($parameterInfo['mapRequestBody']) && $parameterInfo['mapRequestBody'] === true; | ||
$this->arguments->addNewArgument($parameterName, $dataType, ($parameterInfo['optional'] === false), $defaultValue, $mapRequestBody); | ||
$arguments->addNewArgument($parameterName, $dataType, ($parameterInfo['optional'] === false), $defaultValue, $mapRequestBody); | ||
} | ||
} | ||
|
||
|
@@ -390,7 +389,7 @@ protected function getInformationNeededForInitializeActionMethodValidators() | |
* | ||
* @return void | ||
*/ | ||
protected function initializeActionMethodValidators() | ||
protected function initializeActionMethodValidators(Arguments $arguments) | ||
{ | ||
[$validateGroupAnnotations, $actionMethodParameters, $actionValidateAnnotations, $actionIgnoredArguments] = $this->getInformationNeededForInitializeActionMethodValidators(); | ||
|
||
|
@@ -420,7 +419,7 @@ protected function initializeActionMethodValidators() | |
} | ||
|
||
/* @var $argument Argument */ | ||
foreach ($this->arguments as $argument) { | ||
foreach ($arguments as $argument) { | ||
$argumentName = $argument->getName(); | ||
if (isset($ignoredArguments[$argumentName]) && !$ignoredArguments[$argumentName]['evaluate']) { | ||
continue; | ||
|
@@ -515,17 +514,18 @@ protected function initializeAction() | |
* view exists, the view is rendered automatically. | ||
* | ||
* @param ActionRequest $request | ||
* @param ActionResponse $response | ||
* @return ActionResponse | ||
* @param Arguments $arguments | ||
* @param ActionResponse $response The most likely empty response to modify or replace. | ||
* @return ActionResponse The final response for this request. | ||
*/ | ||
protected function callActionMethod(ActionRequest $request, ActionResponse $response): ActionResponse | ||
protected function callActionMethod(ActionRequest $request, Arguments $arguments, ActionResponse $response): ActionResponse | ||
{ | ||
$preparedArguments = []; | ||
foreach ($this->arguments as $argument) { | ||
foreach ($arguments as $argument) { | ||
$preparedArguments[] = $argument->getValue(); | ||
} | ||
|
||
$validationResult = $this->arguments->getValidationResults(); | ||
$validationResult = $arguments->getValidationResults(); | ||
|
||
if (!$validationResult->hasErrors()) { | ||
$actionResult = $this->{$this->actionMethodName}(...$preparedArguments); | ||
|
@@ -560,12 +560,12 @@ protected function callActionMethod(ActionRequest $request, ActionResponse $resp | |
} | ||
|
||
if ($actionResult === null && $this->view instanceof ViewInterface) { | ||
$this->response = $this->renderView($this->response); | ||
$response = $this->renderView($response); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this assignment on |
||
} else { | ||
$this->response->setContent($actionResult); | ||
$response->setContent($actionResult); | ||
} | ||
|
||
return $this->response; | ||
return $response; | ||
} | ||
|
||
/** | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
if someone dared to replace
$this->response
above - not just mutate the object!!! - i dont know what i should think.