Responses
final class Responses (View source)
Provides application controllers with consistently typed responses and one-pass streamed bodies.
Methods
Delegates response and body creation to the framework's PSR-17-backed builder.
Returns UTF-8 plain text with the requested status.
Returns UTF-8 HTML with the requested status.
Encodes a JSON response while preserving Unicode characters and slashes.
Returns an empty response carrying the target Location header.
Opens a file-backed response with attachment and private no-store headers.
Returns a one-pass response whose string-chunk producer starts on first read.
Details
__construct
__construct(ResponseBuilder $builder)
Delegates response and body creation to the framework's PSR-17-backed builder.
text
ResponseInterface
text(string $content, int $status = HttpStatus::OK->value)
Returns UTF-8 plain text with the requested status.
html
ResponseInterface
html(string $content, int $status = HttpStatus::OK->value)
Returns UTF-8 HTML with the requested status.
json
ResponseInterface
json(array $payload, int $status = HttpStatus::OK->value)
Encodes a JSON response while preserving Unicode characters and slashes.
redirect
ResponseInterface
redirect(string $to, int $status = HttpStatus::FOUND->value)
Returns an empty response carrying the target Location header.
download
ResponseInterface
download(string $filePath, string|null $downloadName = null, string $contentType = 'application/octet-stream')
Opens a file-backed response with attachment and private no-store headers.
stream
ResponseInterface
stream(callable $producer, int $status = HttpStatus::OK->value, string $contentType = 'text/plain; charset=UTF-8', array $headers = [])
Returns a one-pass response whose string-chunk producer starts on first read.