From ac60b35f5a5af1e1b773fd97fafe7dd56775c504 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Sun, 27 Oct 2024 21:31:53 +0100 Subject: [PATCH 1/4] BUGFIX: Fix use of `$this->response->set...` in controllers --- Neos.Flow/Classes/Mvc/Controller/ActionController.php | 7 +++++-- .../Tests/Functional/Mvc/ActionControllerTest.php | 10 ++++++++++ .../Controller/ActionControllerTestAController.php | 9 +++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Neos.Flow/Classes/Mvc/Controller/ActionController.php b/Neos.Flow/Classes/Mvc/Controller/ActionController.php index d7b950e748..5e71c8ebc3 100644 --- a/Neos.Flow/Classes/Mvc/Controller/ActionController.php +++ b/Neos.Flow/Classes/Mvc/Controller/ActionController.php @@ -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); @@ -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) { @@ -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; } diff --git a/Neos.Flow/Tests/Functional/Mvc/ActionControllerTest.php b/Neos.Flow/Tests/Functional/Mvc/ActionControllerTest.php index 8b061a43f5..c3db801ceb 100644 --- a/Neos.Flow/Tests/Functional/Mvc/ActionControllerTest.php +++ b/Neos.Flow/Tests/Functional/Mvc/ActionControllerTest.php @@ -129,6 +129,16 @@ public function defaultTemplateIsResolvedAndUsedAccordingToConventions() self::assertEquals('Fourth action example@neos.io', $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 * diff --git a/Neos.Flow/Tests/Functional/Mvc/Fixtures/Controller/ActionControllerTestAController.php b/Neos.Flow/Tests/Functional/Mvc/Fixtures/Controller/ActionControllerTestAController.php index 891c7e2583..6ee689a354 100644 --- a/Neos.Flow/Tests/Functional/Mvc/Fixtures/Controller/ActionControllerTestAController.php +++ b/Neos.Flow/Tests/Functional/Mvc/Fixtures/Controller/ActionControllerTestAController.php @@ -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 From 86ec8bf095f0aab3c23ea73f19f3ed9fed509537 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Sun, 27 Oct 2024 21:33:22 +0100 Subject: [PATCH 2/4] TASK: Remove declaration of obsolete $dispatched state followup to https://github.com/neos/flow-development-collection/pull/3294 --- Neos.Flow/Classes/Mvc/ActionRequest.php | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/Neos.Flow/Classes/Mvc/ActionRequest.php b/Neos.Flow/Classes/Mvc/ActionRequest.php index 738908ba2d..1e1bd68d8f 100644 --- a/Neos.Flow/Classes/Mvc/ActionRequest.php +++ b/Neos.Flow/Classes/Mvc/ActionRequest.php @@ -105,12 +105,6 @@ class ActionRequest */ protected $format = ''; - /** - * If this request has been changed and needs to be dispatched again - * @var boolean - */ - protected $dispatched = false; - /** * The parent request – either another sub ActionRequest a main ActionRequest or null * @var ?ActionRequest @@ -656,14 +650,6 @@ public function getFormat(): string return $this->format; } - /** - * Resets the dispatched status to false - */ - public function __clone() - { - $this->dispatched = false; - } - /** * We provide our own __sleep method, where we serialize all properties *except* the parentRequest if it is * a HTTP request -- as this one contains $_SERVER etc. From d0de9695b4cde772714653d8e7aa0b87c25b2a06 Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Mon, 28 Oct 2024 14:33:29 +0100 Subject: [PATCH 3/4] TASK: Adjust comment --- Neos.Flow/Classes/Mvc/Controller/ActionController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Neos.Flow/Classes/Mvc/Controller/ActionController.php b/Neos.Flow/Classes/Mvc/Controller/ActionController.php index 5e71c8ebc3..55e16ba634 100644 --- a/Neos.Flow/Classes/Mvc/Controller/ActionController.php +++ b/Neos.Flow/Classes/Mvc/Controller/ActionController.php @@ -512,7 +512,7 @@ protected function initializeAction() * * @param ActionRequest $request * @param Arguments $arguments - * @param ResponseInterface $httpResponse The most likely empty response, previously available as $this->response + * @param ActionResponse $response The most likely empty response, previously available as $this->response */ protected function callActionMethod(ActionRequest $request, Arguments $arguments, ActionResponse $response): ResponseInterface { From 96958c29cbe1c240049433c4de1b0721034d6e9e Mon Sep 17 00:00:00 2001 From: mhsdesign <85400359+mhsdesign@users.noreply.github.com> Date: Mon, 28 Oct 2024 14:35:04 +0100 Subject: [PATCH 4/4] TASK: Do not serialise removed `dispatched` state --- Neos.Flow/Classes/Mvc/ActionRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Neos.Flow/Classes/Mvc/ActionRequest.php b/Neos.Flow/Classes/Mvc/ActionRequest.php index 1e1bd68d8f..d3fb98ff25 100644 --- a/Neos.Flow/Classes/Mvc/ActionRequest.php +++ b/Neos.Flow/Classes/Mvc/ActionRequest.php @@ -658,7 +658,7 @@ public function getFormat(): string */ public function __sleep() { - $properties = ['controllerPackageKey', 'controllerSubpackageKey', 'controllerName', 'controllerActionName', 'arguments', 'internalArguments', 'pluginArguments', 'argumentNamespace', 'format', 'dispatched']; + $properties = ['controllerPackageKey', 'controllerSubpackageKey', 'controllerName', 'controllerActionName', 'arguments', 'internalArguments', 'pluginArguments', 'argumentNamespace', 'format']; if ($this->parentRequest instanceof ActionRequest) { $properties[] = 'parentRequest'; }