API / Minn\Http / Failure

Failure final class

Minn\Http\Failure · public/minn/src/Minn/Http/Failure.php · 207 lines

What the public sees when the engine cannot answer: a plain page with no detail, while the detail goes to the log. Installed once per request, it sets PHP's error settings from the debug constants (display stays off unless WP_DEBUG and WP_DEBUG_DISPLAY ask for it) and catches the fatal errors PHP would otherwise print.

Constants and properties

privateFATAL = 4437
privatestatic mixed $recorder
privatestatic bool $display

Whether errors display for this request: display_errors, once the debug constants set it.

privatestatic bool $armed

Whether a failure right now may be recorded against an extension: only while the extensions boot.

Public

staticarmRecovery(): void#

Opens the window in which a failure is an extension's fault: while the plugins and the theme's functions file load and the boot actions fire, code that fails fails for every visitor, so pausing it heals the site. A failure after that (a route, a shortcode, a template) answers to one request's input and is never grounds for a pause; it is logged and the request ends in the error page.

staticdisarmRecovery(): void#

Closes the window armRecovery() opened.

staticonFatal(callable $recorder): void#

What to do with a fatal beyond showing the page: the engine records the extension it came from so the next request loads without it. Installed once the runtime is up, since it needs the database.

$recordercallable(array{type:int,file:string,line:int,message:string}): void
staticinstall(array $constants, array $server): void#

Sets PHP's error settings from the debug constants as the reference's boot does (Runtime\DebugMode), and installs the error handlers. With WP_DEBUG off, or for a request that answers a machine, errors never display. In the first case the reference leaves php.ini's setting; the engine never shows a visitor PHP's errors. Detail is shown only while display_errors is on.

$constantsarray<string, mixed>the debug and request constants, by name
$serverarray<string, mixed>the request's server variables
staticreport(Throwable $error): Minn\Http\Response#

Logs the cause; the page says only that something went wrong.

staticreportJson(Throwable $error): Minn\Http\Response#

The same, for a request that asked for JSON: a client that speaks REST is answered in REST, never handed the HTML error page.

staticinternal(): Minn\Http\Response#

The 500 page.

staticdatabaseUnavailable(): Minn\Http\Response#

The 503 page the reference shows when the database cannot be reached.

staticmaintenance(): Minn\Http\Response#

The 503 page while maintenance mode holds; monitors read the status, the retry hint, and the title.

staticdetailed(string $class, string $message, string $file, int $line): Minn\Http\Response#

The same page with the cause on it, for a site that asked to see errors. Only ever reached when WP_DEBUG_DISPLAY (or WP_DEBUG) is on: a site that has not asked never learns this much from a response.

Internals 5

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privatediscardOutput(): void#

Whatever a half-finished render left in the output buffers goes; the error page must stand alone.

privatenote(Throwable $error): void#

Logs the failure, clears whatever a half-finished render left, and offers it to recovery.

privaterecord(array $error): void#

Hands the failure to the recorder, and never lets recovery itself take the request down: a site that cannot record a pause should still answer with the error page.

$errorarray{type: int, file: string, line: int, message: string}
privatedropin(string $file): Minn\Http\Response#

A drop-in's own page: what it prints, under the status it set (200 when it set none) and only the headers it sent itself, as the reference serves db-error.php when its database is away.

privatepage(int $status, string $title, string $text, string $detail = ''): Minn\Http\Response#