API / Minn\Http / Response

Response final readonly class

Minn\Http\Response · public/minn/src/Minn/Http/Response.php · 133 lines

What a handler returns. Nothing is written to the client until the kernel calls send(), so a response can be inspected, wrapped, or replaced on the way out. Work that belongs after the client has its answer (a cron run a page found due) rides along as afterSend closures.

Uses 2

Constants and properties

propreadonly int $status

Promoted from the constructor.

propreadonly array $headers

Promoted from the constructor.

propreadonly string $body

Promoted from the constructor.

propreadonly array $cookies

Promoted from the constructor.

propreadonly array $afterSend

Promoted from the constructor.

Public

new__construct(int $status = 200, array $headers = array ( ), string $body = '', array $cookies = array ( ), array $afterSend = array ( ))#
$headersarray<string, string>
$cookieslist<array{0: string, 1: string, 2: array}>name, value, setcookie options
$afterSendlist<Closure(): void>run once the response has been handed to the client
statichtml(string $body, int $status = 200): self#

An HTML response.

staticjson(mixed $payload, int $status = 200): self#

A JSON response with the payload encoded.

staticredirect(string $location, int $status = 301): self#

A redirect to a location.

methodwithHeader(string $name, string $value): self#

The same response with one header set, after those already set (one already there keeps its place).

methodwithoutHeader(string $name): self#

The same response without one header.

methodwithCookie(string $name, string $value, array $options): self#

The same response with a cookie to set.

$optionsarray<string, mixed>setcookie options: expires, path, secure, httponly, samesite
methodwithoutBody(): self#

The same response with an empty body, the HEAD answer.

methodafterSend(Closure $work): self#

The same response with work to run once the client has been answered. @param Closure(): void $work

$workClosure(): void
staticemitHeader(string $line): void#

One header line sent now, as plugin code sends one, ahead of the response's own (which win on a shared name). Nothing outside a web request, or once the head is out.

staticwrite(string $bytes): void#

Bytes written to PHP's output now, so into whatever buffers are open: for a page passed through buffers plugin code opened before it (Theme\TemplateBuffer), whose handlers then see it.

methodsendHead(): void#

Writes the status, the headers, and the cookies now, and nothing else: for an answer that code outside the engine may finish on its own (an ajax handler that ends the request), which must find them already said.

methodsend(): void#

Writes the status, the headers, the cookies, and the body, ends the request for the client, then runs the after-send work in the same process (the server that can close the connection first does).