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.
Used by 66 (show)
Constants and properties
| prop | readonly int $status | Promoted from the constructor. |
| prop | readonly array $headers | Promoted from the constructor. |
| prop | readonly string $body | Promoted from the constructor. |
| prop | readonly array $cookies | Promoted from the constructor. |
| prop | readonly array $afterSend | Promoted from the constructor. |
Public
| new | __construct(int $status = 200, array $headers = array ( ), string $body = '', array $cookies = array ( ), array $afterSend = array ( ))# |
| |||||||||
| static | html(string $body, int $status = 200): self# | An HTML response. | |||||||||
| static | json(mixed $payload, int $status = 200): self# | A JSON response with the payload encoded. | |||||||||
| static | redirect(string $location, int $status = 301): self# | A redirect to a location. | |||||||||
| method | withHeader(string $name, string $value): self# | The same response with one header set, after those already set (one already there keeps its place). | |||||||||
| method | withoutHeader(string $name): self# | The same response without one header. | |||||||||
| method | withCookie(string $name, string $value, array $options): self# | The same response with a cookie to set.
| |||||||||
| method | withoutBody(): self# | The same response with an empty body, the HEAD answer. | |||||||||
| method | afterSend(Closure $work): self# | The same response with work to run once the client has been answered. @param Closure(): void $work
| |||||||||
| static | emitHeader(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. | |||||||||
| static | write(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. | |||||||||
| method | sendHead(): 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. | |||||||||
| method | send(): 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). |
Nothing matches.