Skip to content

Commit

Permalink
BUGFIX: Fix use of $this->response->set... in controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Oct 27, 2024
1 parent 3d8e2f1 commit e7ca670
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Classes/Mvc/Controller/ActionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public function processRequest(ActionRequest $request): ResponseInterface
$this->initializeView($this->view);
}

$httpResponse = $this->callActionMethod($request, $this->arguments, $response->buildHttpResponse());
$httpResponse = $this->callActionMethod($request, $this->arguments, $response);

if (!$httpResponse->hasHeader('Content-Type')) {
$httpResponse = $httpResponse->withHeader('Content-Type', $this->negotiatedMediaType);
Expand Down Expand Up @@ -514,7 +514,7 @@ protected function initializeAction()
* @param Arguments $arguments
* @param ResponseInterface $httpResponse The most likely empty response, previously available as $this->response
*/
protected function callActionMethod(ActionRequest $request, Arguments $arguments, ResponseInterface $httpResponse): ResponseInterface
protected function callActionMethod(ActionRequest $request, Arguments $arguments, ActionResponse $response): ResponseInterface
{
$preparedArguments = [];
foreach ($arguments as $argument) {
Expand Down Expand Up @@ -555,6 +555,9 @@ protected function callActionMethod(ActionRequest $request, Arguments $arguments
}
}

// freeze $response previously available as $this->response
$httpResponse = $response->buildHttpResponse();

if ($actionResult instanceof ResponseInterface) {
return $actionResult;
}
Expand Down
10 changes: 10 additions & 0 deletions Tests/Functional/Mvc/ActionControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ public function defaultTemplateIsResolvedAndUsedAccordingToConventions()
self::assertEquals('Fourth action <b>[email protected]</b>', $response->getBody()->getContents());
}

/**
* @test
*/
public function requestAndResponseAreAvailableInTheAction()
{
$response = $this->browser->request('http://localhost/test/mvc/actioncontrollertesta/fifth?argument=the-value');
self::assertEquals('Fifth action (fifth) with: "the-value"', $response->getBody()->getContents());
self::assertEquals('Hello World', $response->getHeaderLine('X-Foo'));
}

/**
* Bug #36913
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ public function fourthAction($emailAddress)
$this->view->assign('emailAddress', $emailAddress);
}

/**
* Tests response and request
*/
public function fifthAction()
{
$this->response->setHttpHeader('X-Foo', 'Hello World');
return sprintf('Fifth action (%s) with: "%s"', $this->request->getControllerActionName(), $this->request->getArgument('argument'));
}

/**
* @param string $putArgument
* @param string $getArgument
Expand Down

0 comments on commit e7ca670

Please sign in to comment.