ResponseBuilder
final class ResponseBuilder (View source)
Builds framework HTTP responses with PSR-17 factories while preserving streaming response bodies
Methods
Initializes the builder with PSR-17 factories for responses and bodies
Creates a text response with the requested status
Creates an HTML response with the requested status
Creates a JSON response while preserving Unicode characters and slashes
Creates a redirect response with its target Location header
Creates a file download response with its headers and a PSR file stream body
Creates a response with content and a Content-Type header
Creates a one-pass response whose producer lazily yields string chunks
Details
__construct
__construct(ResponseFactoryInterface $responseFactory, StreamFactoryInterface $streamFactory)
Initializes the builder with PSR-17 factories for responses and bodies
text
ResponseInterface
text(string $content, int $status = HttpStatus::OK->value)
Creates a text response with the requested status
html
ResponseInterface
html(string $content, int $status = HttpStatus::OK->value)
Creates an HTML response with the requested status
json
ResponseInterface
json(array $payload, int $status = HttpStatus::OK->value)
Creates a JSON response while preserving Unicode characters and slashes
redirect
ResponseInterface
redirect(string $to, int $status = HttpStatus::FOUND->value)
Creates a redirect response with its target Location header
download
ResponseInterface
download(string $filePath, string|null $downloadName = null, string $contentType = 'application/octet-stream')
Creates a file download response with its headers and a PSR file stream body
response
ResponseInterface
response(string $content = '', int $status = HttpStatus::OK->value, string $contentType = 'text/html; charset=UTF-8')
Creates a response with content and a Content-Type header
stream
ResponseInterface
stream(callable $producer, int $status = HttpStatus::OK->value, string $contentType = 'text/plain; charset=UTF-8', array $headers = [])
Creates a one-pass response whose producer lazily yields string chunks