Res
The HTTP response: status code, headers, redirects, and sending html or text.
Status 5
- code Sets the response status code.
- header Sets a response header.
- hasHeader Whether a response header is already set.
- removeHeader Removes a response header.
- ensureCacheControl Sets `Cache-Control: no-store` unless a header is already set.
Output 7
- html Sends HTML and exits.
- json Sends $data as JSON and exits.
- text Sends plain text and exits.
- xml Sends XML and exits.
- svg Sends an SVG image and exits.
- finish Hands the response to the client now, so work after it no longer holds the visitor.
- onShutdown Runs $fn when the script ends, after the response is built.
Status
Res::code(int $code): void
Sets the response status code.
Parameters (1)
| $code | int |
phlat/src/Toolkit/Res.php:17
Res::header(string $name, string $value): void
Sets a response header.
Parameters (2)
| $name | string | |
| $value | string |
phlat/src/Toolkit/Res.php:23
Res::hasHeader(string $name): bool
Whether a response header is already set.
Parameters (1)
| $name | string |
Returns bool
phlat/src/Toolkit/Res.php:29
Res::removeHeader(string $name): void
Removes a response header.
Parameters (1)
| $name | string |
phlat/src/Toolkit/Res.php:39
Res::ensureCacheControl(): void
Sets `Cache-Control: no-store` unless a header is already set.
Every exit below calls it, so no response is cached by accident.
phlat/src/Toolkit/Res.php:45
Redirect
redirect
exitsRes::redirect(string $url, int $code = 302): never
Redirects to $url and exits.
Parameters (2)
| $url | string | |
| $code | int = 302 |
Returns never
phlat/src/Toolkit/Res.php:55
Output
html
exitsRes::html(string $body, int $code = 200): never
Sends HTML and exits.
Parameters (2)
| $body | string | |
| $code | int = 200 |
Returns never
phlat/src/Toolkit/Res.php:66
json
exitsRes::json(mixed $data, int $code = 200): never
Sends $data as JSON and exits.
For request bodies and APIs, never to drive UI.
Parameters (2)
| $data | mixed | |
| $code | int = 200 |
Returns never
phlat/src/Toolkit/Res.php:76
text
exitsRes::text(string $body, int $code = 200): never
Sends plain text and exits.
Parameters (2)
| $body | string | |
| $code | int = 200 |
Returns never
phlat/src/Toolkit/Res.php:86
xml
exitsRes::xml(string $body, int $code = 200): never
Sends XML and exits.
Parameters (2)
| $body | string | |
| $code | int = 200 |
Returns never
phlat/src/Toolkit/Res.php:96
svg
exitsRes::svg(string $body, int $code = 200): never
Sends an SVG image and exits.
Parameters (2)
| $body | string | |
| $code | int = 200 |
Returns never
phlat/src/Toolkit/Res.php:106
Res::finish(): void
Hands the response to the client now, so work after it no longer holds the visitor.
Does nothing outside PHP-FPM.
phlat/src/Toolkit/Res.php:116
Res::onShutdown(callable $fn): void
Runs $fn when the script ends, after the response is built.
Parameters (1)
| $fn | callable |
phlat/src/Toolkit/Res.php:123