Skip to content

Commit

Permalink
TASK: Revert introduction of SpecialResponsesSupport
Browse files Browse the repository at this point in the history
Will be split up into an own pr #3298
  • Loading branch information
mhsdesign committed Feb 3, 2024
1 parent 82caa27 commit c96fd84
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 112 deletions.
41 changes: 30 additions & 11 deletions Neos.Flow/Classes/Mvc/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
*/
abstract class AbstractController implements ControllerInterface
{
use SpecialResponsesSupport;

/**
* @var UriBuilder
*/
Expand Down Expand Up @@ -232,6 +230,23 @@ protected function forward(string $actionName, string $controllerName = null, st
$this->forwardToRequest($nextRequest);

Check failure on line 230 in Neos.Flow/Classes/Mvc/Controller/AbstractController.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test static analysis (deps: highest)

Method Neos\Flow\Mvc\Controller\AbstractController::forward() should always throw an exception or terminate script execution but doesn't do that.
}

/**
* Forwards the request to another action and / or controller.
*
* Request is directly transfered to the other action / controller
*
* @param ActionRequest $request The request to redirect to
* @return void
* @throws ForwardException
* @see redirectToRequest()
* @api
*/
protected function forwardToRequest(ActionRequest $request)
{
$nextRequest = clone $request;
throw ForwardException::createForNextRequest($nextRequest, '');
}

/**
* Redirects the request to another action and / or controller.
*
Expand Down Expand Up @@ -308,12 +323,16 @@ protected function redirectToRequest(ActionRequest $request, int $delay = 0, int
*/
protected function redirectToUri(string|UriInterface $uri, int $delay = 0, int $statusCode = 303): never
{
if (!$uri instanceof UriInterface) {
$uri = new Uri($uri);
if ($delay === 0) {
if (!$uri instanceof UriInterface) {
$uri = new Uri($uri);
}
$this->response->setRedirectUri($uri, $statusCode);
} else {
$this->response->setStatusCode($statusCode);
$this->response->setContent('<html><head><meta http-equiv="refresh" content="' . (int)$delay . ';url=' . $uri . '"/></head></html>');
}

$response = $this->responseRedirectsToUri($uri, $delay, $statusCode, $this->response);
$this->throwStopActionWithResponse($response, '');
throw StopActionException::createForResponse($this->response, '');
}

/**
Expand All @@ -325,20 +344,20 @@ protected function redirectToUri(string|UriInterface $uri, int $delay = 0, int $
* @param string $statusMessage A custom HTTP status message
* @param string $content Body content which further explains the status
* @throws StopActionException
* @deprecated Use SpecialResponsesSupport::responseThrowsStatus
* @see SpecialResponsesSupport::responseThrowsStatus
* @api
*/
protected function throwStatus(int $statusCode, $statusMessage = null, $content = null): never
{
$this->response->setStatusCode($statusCode);
if ($content === null) {
$content = sprintf(
'%s %s',
$statusCode,
$statusMessage ?? ResponseInformationHelper::getStatusMessageByCode($statusCode)
);
}

$this->responseThrowsStatus($statusCode, $content, $this->response);
$this->response->setContent($content);
throw StopActionException::createForResponse($this->response, $content);
}

/**
Expand Down
19 changes: 9 additions & 10 deletions Neos.Flow/Classes/Mvc/Controller/RestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,15 @@ protected function initializeUpdateAction()
*/
protected function redirectToUri(string|UriInterface $uri, int $delay = 0, int $statusCode = 303): never
{
if (!$uri instanceof UriInterface) {
$uri = new Uri($uri);
}

$response = $this->responseRedirectsToUri($uri, $delay, $statusCode, $this->response);
if ($this->request->getFormat() === 'json') {
// send empty body on redirects for JSON requests
$response->setContent('');
// the parent method throws the exception, but we need to act afterwards
// thus the code in catch - it's the expected state
try {
parent::redirectToUri($uri, $delay, $statusCode);
} catch (StopActionException $exception) {
if ($this->request->getFormat() === 'json') {
$exception->response->setContent('');
}
throw $exception;
}

$this->throwStopActionWithResponse($response, '');
}
}
88 changes: 0 additions & 88 deletions Neos.Flow/Classes/Mvc/Controller/SpecialResponsesSupport.php

This file was deleted.

3 changes: 2 additions & 1 deletion Neos.Flow/Classes/Mvc/Exception/ForwardException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
* source code.
*/
use Neos\Flow\Mvc\ActionRequest;
use Neos\Flow\Mvc\Controller\AbstractController;

/**
* This exception is thrown by a controller to stop the execution of the current
* action and return the control to the dispatcher for the special case of a forward.
*
* See {@see SpecialResponsesSupport::forwardToRequest()} for more information.
* See {@see AbstractController::forward()} for more information.
*
* Other control flow exceptions: {@see StopActionException}
*
Expand Down
4 changes: 2 additions & 2 deletions Neos.Flow/Classes/Mvc/Exception/StopActionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
*/

use Neos\Flow\Mvc\ActionResponse;
use Neos\Flow\Mvc\Controller\AbstractController;

/**
* This exception is thrown by a controller to stop the execution of the current
* action and return the control to the dispatcher. The dispatcher catches this
* exception and - depending on the "dispatched" status of the request - either
* continues dispatching the request or returns control to the request handler.
*
* See {@see SpecialResponsesSupport::throwStopActionWithResponse()}
* or {@see SpecialResponsesSupport::responseRedirectsToUri()} for more information.
* See {@see AbstractController::throwStatus()} or {@see AbstractController::redirectToUri()} for more information.
*
* Other control flow exceptions: {@see ForwardException}
*
Expand Down

0 comments on commit c96fd84

Please sign in to comment.