final class ActionResponse (View source)

deprecated with Flow 9

The legacy MVC response object.

Previously Flows MVC needed a single mutable response which was passed from dispatcher to controllers and even further to the view and other places via the controller context: {\Neos\Flow\Mvc\Controller\ControllerContext::getResponse()}. This allowed to manipulate the response at every place.

With the dispatcher and controllers now directly returning a response, the mutability is no longer required. Additionally, the abstraction offers naturally nothing, that cant be archived by the psr response, as it directly translates to one: {[\Neos\Flow\Mvc\ActionResponse::buildHttpResponse()}

So](../../../Neos/Flow/Mvc/ActionResponse.html) you can and should use the immutable psr {\Psr\Http\Message\ResponseInterface} instead where-ever possible.

For backwards compatibility, each controller will might now manage an own instance of the action response via $this->response {\Neos\Flow\Mvc\Controller\AbstractController::$response} and pass it along to places. But this behaviour is deprecated!

Instead, you can directly return a PSR repose {\GuzzleHttp\Psr7\Response} from a controller:

public function myAction()
{
    return (new Response(status: 200, body: $output))
        ->withAddedHeader('X-My-Header', 'foo');
}

Properties

protected StreamInterface $content
protected UriInterface $redirectUri
protected int|null $statusCode

The HTTP status code

protected string $contentType
protected Cookie[] $cookies
protected array $headers
protected ResponseInterface|null $httpResponse

Methods

__construct()

No description

void
setContent(string|StreamInterface $content) deprecated

No description

void
setContentType(string $contentType) deprecated

Set content mime type for this response.

void
setRedirectUri(UriInterface $uri, int $statusCode = 303) deprecated

Set a redirect URI and according status for this response.

void
setStatusCode(int $statusCode) deprecated

Set the status code for this response as HTTP status code.

void
setCookie(Cookie $cookie) deprecated

Set a cookie in the HTTP response This leads to a corresponding Set-Cookie header to be set in the HTTP response

void
deleteCookie(string $cookieName) deprecated

Delete a cooke from the HTTP response This leads to a corresponding Set-Cookie header with an expired Cookie to be set in the HTTP response

void
setHttpHeader(string $headerName, array|string|DateTime $headerValue)

Set the specified header in the response, overwriting any previous value set for this header.

void
addHttpHeader(string $headerName, array|string|DateTime $headerValue)

Add the specified header to the response, without overwriting any previous value set for this header.

array|string|null
getHttpHeader(string $headerName)

Return the specified HTTP header that was previously set.

string
getContent()

No description

UriInterface|null
getRedirectUri()

No description

int
getStatusCode()

No description

bool
hasContentType()

No description

string
getContentType()

No description

void
replaceHttpResponse(ResponseInterface $response)

Unsafe. Please avoid the use of this escape hatch as the behaviour is partly unspecified https://github.com/neos/flow-development-collection/issues/2492

mergeIntoParentResponse(ActionResponse $actionResponse)

No description

ResponseInterface
buildHttpResponse()

During the migration of {ActionResponse} to {HttpResponse} this might come in handy.

Details

__construct()

No description

void setContent(string|StreamInterface $content) deprecated

deprecated please use {@see \Psr\Http\Message\ResponseInterface::withBody()} in combination with {@see \GuzzleHttp\Psr7\Utils::streamFor} instead

No description

Parameters

string|StreamInterface $content

Return Value

void

void setContentType(string $contentType) deprecated

deprecated please use {@see \Psr\Http\Message\ResponseInterface::withHeader()} with "Content-Type" instead.

Set content mime type for this response.

Parameters

string $contentType

Return Value

void

void setRedirectUri(UriInterface $uri, int $statusCode = 303) deprecated

deprecated please use {@see \Psr\Http\Message\ResponseInterface::withStatus()} and {@see \Psr\Http\Message\ResponseInterface::withHeader()} with "Header" instead.

Set a redirect URI and according status for this response.

Parameters

UriInterface $uri
int $statusCode

Return Value

void

void setStatusCode(int $statusCode) deprecated

deprecated please use {@see \Psr\Http\Message\ResponseInterface::withStatus()} instead.

Set the status code for this response as HTTP status code.

Other codes than HTTP status may end in unpredictable results.

Parameters

int $statusCode

Return Value

void

void setCookie(Cookie $cookie) deprecated

deprecated please use {@see \Psr\Http\Message\ResponseInterface::withHeader()} with "Set-Cookie" instead.

Set a cookie in the HTTP response This leads to a corresponding Set-Cookie header to be set in the HTTP response

Parameters

Cookie $cookie

Cookie to be set in the HTTP response

Return Value

void

void deleteCookie(string $cookieName) deprecated

deprecated

Delete a cooke from the HTTP response This leads to a corresponding Set-Cookie header with an expired Cookie to be set in the HTTP response

Parameters

string $cookieName

Name of the cookie to delete

Return Value

void

void setHttpHeader(string $headerName, array|string|DateTime $headerValue)

Set the specified header in the response, overwriting any previous value set for this header.

This behaviour is unsafe and partially unspecified: https://github.com/neos/flow-development-collection/issues/2492

Parameters

string $headerName

The name of the header to set

array|string|DateTime $headerValue

An array of values or a single value for the specified header field

Return Value

void

void addHttpHeader(string $headerName, array|string|DateTime $headerValue)

Add the specified header to the response, without overwriting any previous value set for this header.

This behaviour is unsafe and partially unspecified: https://github.com/neos/flow-development-collection/issues/2492

Parameters

string $headerName

The name of the header to set

array|string|DateTime $headerValue

An array of values or a single value for the specified header field

Return Value

void

array|string|null getHttpHeader(string $headerName)

Return the specified HTTP header that was previously set.

Parameters

string $headerName

The name of the header to get the value(s) for

Return Value

array|string|null

An array of field values if multiple headers of that name exist, a string value if only one value exists and NULL if there is no such header.

string getContent()

No description

Return Value

string

UriInterface|null getRedirectUri()

No description

Return Value

UriInterface|null

int getStatusCode()

No description

Return Value

int

bool hasContentType()

No description

Return Value

bool

string getContentType()

No description

Return Value

string

void replaceHttpResponse(ResponseInterface $response)

Unsafe. Please avoid the use of this escape hatch as the behaviour is partly unspecified https://github.com/neos/flow-development-collection/issues/2492

Parameters

ResponseInterface $response

Return Value

void

ActionResponse mergeIntoParentResponse(ActionResponse $actionResponse)

No description

Parameters

ActionResponse $actionResponse

Return Value

ActionResponse

ResponseInterface buildHttpResponse()

During the migration of {ActionResponse} to {HttpResponse} this might come in handy.

Note this is a special use case method that will apply the internal properties (Content-Type, StatusCode, Location, Set-Cookie and Content) to a new or replaced PSR-7 Response and return it.

Possibly unsafe when used in combination with {\Neos\Flow\Mvc\self::replaceHttpResponse()} https://github.com/neos/flow-development-collection/issues/2492

Return Value

ResponseInterface