final class ActionResponse (View source)

The minimal MVC response object.

It allows for simple interactions with the HTTP response from within MVC actions. More specific requirements can be implemented via HTTP middlewares.

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)

No description

void
setContentType(string $contentType)

Set content mime type for this response.

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

Set a redirect URI and according status for this response.

void
setStatusCode(int $statusCode)

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

void
setCookie(Cookie $cookie)

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)

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
setComponentParameter(string $componentClassName, string $parameterName, mixed $value) deprecated

Set a (HTTP) component parameter for use later in the chain.

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)

Use this if you want build your own HTTP Response inside your action

mergeIntoParentResponse(ActionResponse $actionResponse)

No description

ResponseInterface
buildHttpResponse()

Note this is a special use case method that will apply the internal properties (Content-Type, StatusCode, Location, Set-Cookie and Content) to the given PSR-7 Response and return a modified response. This is used to merge the ActionResponse properties into a possible HttpResponse created in a View (see ActionController::renderView()) because those would be overwritten otherwise. Note that any component parameters will still run through the component chain and will not be propagated here.

Details

__construct()

No description

void setContent(string|StreamInterface $content)

No description

Parameters

string|StreamInterface $content

Return Value

void

void setContentType(string $contentType)

Set content mime type for this response.

Parameters

string $contentType

Return Value

void

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

Set a redirect URI and according status for this response.

Parameters

UriInterface $uri
int $statusCode

Return Value

void

void setStatusCode(int $statusCode)

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)

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)

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 setComponentParameter(string $componentClassName, string $parameterName, mixed $value) deprecated

deprecated since Flow 7.0 use setHttpHeader or replaceHttpResponse instead. For now this will still work with $componentClassName of "SetHeaderComponent" or "ReplaceHttpResponseComponent" only.

Set a (HTTP) component parameter for use later in the chain.

This can be used to adjust all aspects of the later processing if needed.

Parameters

string $componentClassName
string $parameterName
mixed $value

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.

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.

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)

Use this if you want build your own HTTP Response inside your action

Parameters

ResponseInterface $response

Return Value

void

ActionResponse mergeIntoParentResponse(ActionResponse $actionResponse)

No description

Parameters

ActionResponse $actionResponse

Return Value

ActionResponse

ResponseInterface buildHttpResponse()

internal  
 

Note this is a special use case method that will apply the internal properties (Content-Type, StatusCode, Location, Set-Cookie and Content) to the given PSR-7 Response and return a modified response. This is used to merge the ActionResponse properties into a possible HttpResponse created in a View (see ActionController::renderView()) because those would be overwritten otherwise. Note that any component parameters will still run through the component chain and will not be propagated here.

Return Value

ResponseInterface