WebResponseInterface
The response an action or view writes to: body, status, headers, cookies, redirect and content type, plus the conversion to PSR-7 the runtime emits.
Narrower than WebResponse: its serialization hooks, parameter holder and worker-reset behaviour serve the framework’s own plumbing, not the code composing a response.
Named for the framework’s response rather than PSR-7’s, which WebResponse is not — it is mutable by design, being the thing an action progressively fills in. Convert with WebResponseInterface::toPsrResponse() at the point a real PSR-7 message is wanted.
Synopsis
Section titled “Synopsis”interface WebResponseInterface
| Implemented by | WebResponse |
| Since | 3.2.0 |
| Source | Response/WebResponseInterface.php |
Methods
Section titled “Methods”| Method | Description |
|---|---|
addHttpHeader(string $name, mixed $value): mixed | Add a header value, keeping any already set. |
appendContent(mixed $content): mixed | Append to a string body. |
clearContent(): mixed | Discard the body. |
clearRedirect(): mixed | Discard any queued redirect. |
getContent(): mixed | The response body: a string, a scalar, a stream resource, or null when unset. |
getContentType(): ?string | The response’s Content-Type. |
getCookies(): array<string, mixed> | Every queued cookie definition, keyed by name. |
getHttpHeader(string $name): ?list<string> | All values of one header, or null when unset. |
getHttpHeaders(): array<string, list<string>> | Every header set on this response. |
getHttpStatusCode(): string | The status code, as a numeric string. |
getOutputType(): ?OutputType | The output type this response is being rendered in. |
| [`getRedirect(): ?array{location: string, code: (int | string)}`](#getredirect) |
hasContent(): bool | Whether a body has been set. |
hasHttpHeader(string $name): bool | Whether a header is set. |
hasRedirect(): bool | Whether a redirect is queued. |
prependContent(mixed $content): mixed | Prepend to a string body. |
removeHttpHeader(string $name): mixed | Remove a header. |
setContent(mixed $content): mixed | Replace the body. |
setContentType(string $type): mixed | Set the response’s Content-Type. |
| [`setCookie(string $name, mixed $value, int | string |
setHttpHeader(string $name, mixed $value, bool $replace = true): mixed | Set a header, replacing any existing values unless $replace is false. |
| [`setHttpStatusCode(string | int $code): mixed`](#sethttpstatuscode) |
setOutputType(OutputType $outputType): mixed | Set the output type this response is being rendered in. |
| [`setRedirect(mixed $location, int | string $code = 302): mixed`](#setredirect) |
toPsrResponse(?OutputType $outputType = null): ResponseInterface | Materialize this response as PSR-7, with no side effects on any output channel. |
unsetCookie(string $name, ?string $path = null, ?string $domain = null, ?bool $secure = null, ?bool $httponly = null): mixed | Queue a cookie deletion. |
addHttpHeader()
Section titled “addHttpHeader()”abstract public function addHttpHeader(string $name, mixed $value): mixed
Add a header value, keeping any already set.
| Parameter | Type | Description |
|---|---|---|
$name | string | |
$value | mixed |
Returns mixed
appendContent()
Section titled “appendContent()”abstract public function appendContent(mixed $content): mixed
Append to a string body.
| Parameter | Type | Description |
|---|---|---|
$content | mixed |
Returns mixed
clearContent()
Section titled “clearContent()”abstract public function clearContent(): mixed
Discard the body.
Returns mixed
clearRedirect()
Section titled “clearRedirect()”abstract public function clearRedirect(): mixed
Discard any queued redirect.
Returns mixed
getContent()
Section titled “getContent()”abstract public function getContent(): mixed
The response body: a string, a scalar, a stream resource, or null when unset.
Returns mixed
getContentType()
Section titled “getContentType()”abstract public function getContentType(): ?string
The response’s Content-Type.
Returns ?``string
getCookies()
Section titled “getCookies()”abstract public function getCookies(): array<string, mixed>
Every queued cookie definition, keyed by name.
Returns array``<``string``, ``mixed``>
getHttpHeader()
Section titled “getHttpHeader()”abstract public function getHttpHeader(string $name): ?list<string>
All values of one header, or null when unset.
| Parameter | Type | Description |
|---|---|---|
$name | string |
Returns ?``list``<``string``>
getHttpHeaders()
Section titled “getHttpHeaders()”abstract public function getHttpHeaders(): array<string, list<string>>
Every header set on this response.
Returns array``<``string``, ``list``<``string``>``>
getHttpStatusCode()
Section titled “getHttpStatusCode()”abstract public function getHttpStatusCode(): string
The status code, as a numeric string.
Returns string
getOutputType()
Section titled “getOutputType()”abstract public function getOutputType(): ?OutputType
The output type this response is being rendered in.
Returns ?OutputType
getRedirect()
Section titled “getRedirect()”abstract public function getRedirect(): ?array{location: string, code: (int | string)}
The queued redirect, or null when none is set.
Returns ?``array{location: string, code: (int | string)}
hasContent()
Section titled “hasContent()”abstract public function hasContent(): bool
Whether a body has been set.
Returns bool
hasHttpHeader()
Section titled “hasHttpHeader()”abstract public function hasHttpHeader(string $name): bool
Whether a header is set.
| Parameter | Type | Description |
|---|---|---|
$name | string |
Returns bool
hasRedirect()
Section titled “hasRedirect()”abstract public function hasRedirect(): bool
Whether a redirect is queued.
Returns bool
prependContent()
Section titled “prependContent()”abstract public function prependContent(mixed $content): mixed
Prepend to a string body.
| Parameter | Type | Description |
|---|---|---|
$content | mixed |
Returns mixed
removeHttpHeader()
Section titled “removeHttpHeader()”abstract public function removeHttpHeader(string $name): mixed
Remove a header.
| Parameter | Type | Description |
|---|---|---|
$name | string |
Returns mixed
setContent()
Section titled “setContent()”abstract public function setContent(mixed $content): mixed
Replace the body.
| Parameter | Type | Description |
|---|---|---|
$content | mixed |
Returns mixed
setContentType()
Section titled “setContentType()”abstract public function setContentType(string $type): mixed
Set the response’s Content-Type.
| Parameter | Type | Description |
|---|---|---|
$type | string |
Returns mixed
setCookie()
Section titled “setCookie()”abstract public function setCookie(string $name, mixed $value, int|string|null $lifetime = null, ?string $path = null, ?string $domain = null, ?bool $secure = null, ?bool $httponly = null, callable|false|null $encodeCallback = null, ?string $samesite = null): mixed
Queue a cookie.
| Parameter | Type | Description |
|---|---|---|
$name | string | |
$value | mixed | Null, false or the empty string deletes the cookie. |
$lifetime | `int“ | string |
$path | ?``string | |
$domain | ?``string | |
$secure | ?``bool | |
$httponly | ?``bool | |
$encodeCallback | `callable“ | false |
$samesite | ?``string |
Returns mixed
setHttpHeader()
Section titled “setHttpHeader()”abstract public function setHttpHeader(string $name, mixed $value, bool $replace = true): mixed
Set a header, replacing any existing values unless $replace is false.
| Parameter | Type | Description |
|---|---|---|
$name | string | |
$value | mixed | |
$replace | bool |
Returns mixed
setHttpStatusCode()
Section titled “setHttpStatusCode()”abstract public function setHttpStatusCode(string|int $code): mixed
Set the status code.
| Parameter | Type | Description |
|---|---|---|
$code | `string“ | “int` |
Returns mixed
| Throws | When |
|---|---|
QuioteException | For a code outside the acceptable range. |
setOutputType()
Section titled “setOutputType()”abstract public function setOutputType(OutputType $outputType): mixed
Set the output type this response is being rendered in.
| Parameter | Type | Description |
|---|---|---|
$outputType | OutputType |
Returns mixed
setRedirect()
Section titled “setRedirect()”abstract public function setRedirect(mixed $location, int|string $code = 302): mixed
Redirect to $location with $code.
| Parameter | Type | Description |
|---|---|---|
$location | mixed | |
$code | `int“ | “string` |
Returns mixed
| Throws | When |
|---|---|
QuioteException | For a code outside the acceptable range. |
toPsrResponse()
Section titled “toPsrResponse()”abstract public function toPsrResponse(?OutputType $outputType = null): ResponseInterface
Materialize this response as PSR-7, with no side effects on any output channel.
Output type whose headers to fold in; defaults to this response’s own.
| Parameter | Type | Description |
|---|---|---|
$outputType | ?OutputType | Output type whose headers to fold in; defaults to this response’s own. |
Returns ResponseInterface
unsetCookie()
Section titled “unsetCookie()”abstract public function unsetCookie(string $name, ?string $path = null, ?string $domain = null, ?bool $secure = null, ?bool $httponly = null): mixed
Queue a cookie deletion.
| Parameter | Type | Description |
|---|---|---|
$name | string | |
$path | ?``string | |
$domain | ?``string | |
$secure | ?``bool | |
$httponly | ?``bool |
Returns mixed