Documentation

ErrorHandler
in package

Handles rendering the exception page as well as logging errors.

Tags
author

Samerton

author

Aberdeener

version
2.0.0-pr9
license

MIT

Table of Contents

Constants

LINE_BUFFER  = 20
Defined for easy changing.

Methods

catchError()  : bool
Catch an error. If it is a fatal error, pass execution to catchException(), otherwise make a log entry.
catchException()  : void
Used to neatly display exceptions/errors and the trace/frames leading up to it.
catchShutdownError()  : void
Called at end of every execution on page load.
logCustomError()  : void
Log a custom error, uses `other` type.
logWarning()  : void
Write a message to the 'warning' log.
parseFrame()  : array<string|int, mixed>
Returns frame array from specified information.
logError()  : void
Write error to specific log file.
parseFile()  : string
Create purified and truncated string from a file for use with error source code preview.
shouldUsePlainText()  : bool
For API requests, query requests and AJAX requests, return a plain text error message.

Constants

LINE_BUFFER

Defined for easy changing.

private mixed LINE_BUFFER = 20

This constant indicates how many LOC from each frame's PHP file to show before and after the highlighted line.

Methods

catchError()

Catch an error. If it is a fatal error, pass execution to catchException(), otherwise make a log entry.

public static catchError(int $error_number, string $error_string, string $error_file, int $error_line) : bool
Parameters
$error_number : int

PHP universal error number of this error.

$error_string : string

Error message.

$error_file : string

Path of file which this error was thrown at.

$error_line : int

Line of $error_file which error occurred at.

Return values
bool

False if error reporting is disabled, true otherwise.

catchException()

Used to neatly display exceptions/errors and the trace/frames leading up to it.

public static catchException(Throwable|null $exception[, string|null $error_string = null ][, string|null $error_file = null ][, int|null $error_line = null ]) : void

If this is called manually, the error_string, error_file and error_line must be manually provided, and a single trace frame will be generated for it.

Parameters
$exception : Throwable|null

Exception/Error to catch and render trace from. If null, other variables will be used to render trace.

$error_string : string|null = null

Main error message to be shown on top of page. Used when $exception is null.

$error_file : string|null = null

Path to most recent frame's file. Used when $exception is null.

$error_line : int|null = null

Line in $error_file which caused Exception. Used when $exception is null.

catchShutdownError()

Called at end of every execution on page load.

public static catchShutdownError() : void

If an error exists, and the type is fatal, pass execution to catchException().

logCustomError()

Log a custom error, uses `other` type.

public static logCustomError(string $contents) : void

Not used internally, only for modules to use.

Parameters
$contents : string

Error to write to file.

logWarning()

Write a message to the 'warning' log.

public static logWarning(string $contents) : void
Parameters
$contents : string

Warning to write to file.

parseFrame()

Returns frame array from specified information.

public static parseFrame(Throwable|null $exception, string $frame_file, int $frame_line[, int|null $number = null ]) : array<string|int, mixed>

Leaving number as null will use Exception trace count + 1 (for most recent frame).

Parameters
$exception : Throwable|null

Exception object caught and whose trace to count. If null, $number will be used for frame number.

$frame_file : string

Path to file which was referenced in this frame.

$frame_line : int

Line number of $frame_file which Exception was thrown at.

$number : int|null = null

Higher number = more recent frame. If null, will use $exception trace count + 1.

Return values
array<string|int, mixed>

This frame in an array form.

logError()

Write error to specific log file.

private static logError(string $type, string $contents) : void
Parameters
$type : string

Which category/file to log this to. Must be: warning, notice, other or fatal.

$contents : string

The message to be saved.

parseFile()

Create purified and truncated string from a file for use with error source code preview.

private static parseFile(array<string|int, mixed>|bool $lines, int $error_line) : string
Parameters
$lines : array<string|int, mixed>|bool

Array of lines in this file. If false, will return nothing (means PHP cannot access file).

$error_line : int

Line to center output around.

Return values
string

Truncated string from this file.

shouldUsePlainText()

For API requests, query requests and AJAX requests, return a plain text error message.

private static shouldUsePlainText() : bool
Return values
bool

Whether the error page should be in plain text rather than a user friendly HTML page.


        
On this page

Search results