Skip to content

PsrResponseBuilder

Assembles a PSR-7 response from already-resolved status, headers, cookies and body.

The translation step every runtime shares, with no side effects on any output channel and no dependency on a context, a request or response state: everything it needs arrives as a plain value. Deciding what the status and headers should be belongs to WebResponse; turning that decision into a PSR-7 message belongs here.

final class PsrResponseBuilder

Since3.2.0
SourceResponse/PsrResponseBuilder.php
MethodDescription
[`build(int $status, array<string, liststring> $headers, list $setCookieLines, mixed $content, bool $withBody = true, ?string $sendfileHeaderName = null): ResponseInterface`](#build)

public function build(int $status, array<string, list<string>|string> $headers, list<string> $setCookieLines, mixed $content, bool $withBody = true, ?string $sendfileHeaderName = null): ResponseInterface

When set and $content is a plain-file resource, the file’s path is handed to the front-end server through this header and no body is emitted.

ParameterTypeDescription
$statusintStatus code, already validated.
$headers`array<string, list<string>string>`
$setCookieLineslist``<``string``>Serialized Set-Cookie values.
$contentmixedString, scalar, stream resource, or null.
$withBodyboolFalse to emit headers only (a redirect, typically).
$sendfileHeaderName?``stringWhen set and $content is a plain-file resource, the file’s path is handed to the front-end server through this header and no body is emitted.

Returns ResponseInterface