Skip to content

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.

interface WebResponseInterface

Implemented byWebResponse
Since3.2.0
SourceResponse/WebResponseInterface.php
MethodDescription
addHttpHeader(string $name, mixed $value): mixedAdd a header value, keeping any already set.
appendContent(mixed $content): mixedAppend to a string body.
clearContent(): mixedDiscard the body.
clearRedirect(): mixedDiscard any queued redirect.
getContent(): mixedThe response body: a string, a scalar, a stream resource, or null when unset.
getContentType(): ?stringThe 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(): stringThe status code, as a numeric string.
getOutputType(): ?OutputTypeThe output type this response is being rendered in.
[`getRedirect(): ?array{location: string, code: (intstring)}`](#getredirect)
hasContent(): boolWhether a body has been set.
hasHttpHeader(string $name): boolWhether a header is set.
hasRedirect(): boolWhether a redirect is queued.
prependContent(mixed $content): mixedPrepend to a string body.
removeHttpHeader(string $name): mixedRemove a header.
setContent(mixed $content): mixedReplace the body.
setContentType(string $type): mixedSet the response’s Content-Type.
[`setCookie(string $name, mixed $value, intstring
setHttpHeader(string $name, mixed $value, bool $replace = true): mixedSet a header, replacing any existing values unless $replace is false.
[`setHttpStatusCode(stringint $code): mixed`](#sethttpstatuscode)
setOutputType(OutputType $outputType): mixedSet the output type this response is being rendered in.
[`setRedirect(mixed $location, intstring $code = 302): mixed`](#setredirect)
toPsrResponse(?OutputType $outputType = null): ResponseInterfaceMaterialize 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): mixedQueue a cookie deletion.

abstract public function addHttpHeader(string $name, mixed $value): mixed

Add a header value, keeping any already set.

ParameterTypeDescription
$namestring
$valuemixed

Returns mixed

abstract public function appendContent(mixed $content): mixed

Append to a string body.

ParameterTypeDescription
$contentmixed

Returns mixed

abstract public function clearContent(): mixed

Discard the body.

Returns mixed

abstract public function clearRedirect(): mixed

Discard any queued redirect.

Returns mixed

abstract public function getContent(): mixed

The response body: a string, a scalar, a stream resource, or null when unset.

Returns mixed

abstract public function getContentType(): ?string

The response’s Content-Type.

Returns ?``string

abstract public function getCookies(): array<string, mixed>

Every queued cookie definition, keyed by name.

Returns array``<``string``, ``mixed``>

abstract public function getHttpHeader(string $name): ?list<string>

All values of one header, or null when unset.

ParameterTypeDescription
$namestring

Returns ?``list``<``string``>

abstract public function getHttpHeaders(): array<string, list<string>>

Every header set on this response.

Returns array``<``string``, ``list``<``string``>``>

abstract public function getHttpStatusCode(): string

The status code, as a numeric string.

Returns string

abstract public function getOutputType(): ?OutputType

The output type this response is being rendered in.

Returns ?OutputType

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)}

abstract public function hasContent(): bool

Whether a body has been set.

Returns bool

abstract public function hasHttpHeader(string $name): bool

Whether a header is set.

ParameterTypeDescription
$namestring

Returns bool

abstract public function hasRedirect(): bool

Whether a redirect is queued.

Returns bool

abstract public function prependContent(mixed $content): mixed

Prepend to a string body.

ParameterTypeDescription
$contentmixed

Returns mixed

abstract public function removeHttpHeader(string $name): mixed

Remove a header.

ParameterTypeDescription
$namestring

Returns mixed

abstract public function setContent(mixed $content): mixed

Replace the body.

ParameterTypeDescription
$contentmixed

Returns mixed

abstract public function setContentType(string $type): mixed

Set the response’s Content-Type.

ParameterTypeDescription
$typestring

Returns mixed

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.

ParameterTypeDescription
$namestring
$valuemixedNull, 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

abstract public function setHttpHeader(string $name, mixed $value, bool $replace = true): mixed

Set a header, replacing any existing values unless $replace is false.

ParameterTypeDescription
$namestring
$valuemixed
$replacebool

Returns mixed

abstract public function setHttpStatusCode(string|int $code): mixed

Set the status code.

ParameterTypeDescription
$code`string““int`

Returns mixed

ThrowsWhen
QuioteExceptionFor a code outside the acceptable range.

abstract public function setOutputType(OutputType $outputType): mixed

Set the output type this response is being rendered in.

ParameterTypeDescription
$outputTypeOutputType

Returns mixed

abstract public function setRedirect(mixed $location, int|string $code = 302): mixed

Redirect to $location with $code.

ParameterTypeDescription
$locationmixed
$code`int““string`

Returns mixed

ThrowsWhen
QuioteExceptionFor a code outside the acceptable range.

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.

ParameterTypeDescription
$outputType?OutputTypeOutput type whose headers to fold in; defaults to this response’s own.

Returns ResponseInterface

abstract public function unsetCookie(string $name, ?string $path = null, ?string $domain = null, ?bool $secure = null, ?bool $httponly = null): mixed

Queue a cookie deletion.

ParameterTypeDescription
$namestring
$path?``string
$domain?``string
$secure?``bool
$httponly?``bool

Returns mixed