ErrorHandler
in package
Global error and exception handler with email notifications.
Registers PHP error, exception, and fatal shutdown handlers. When ERROR_EMAIL is set in .env, sends error details via email.
Tags
Table of Contents
Properties
- $errorEmail : string|null
Methods
- handleError() : bool
- Handle PHP errors (warnings, notices, etc.).
- handleException() : void
- Handle uncaught exceptions.
- handleShutdown() : void
- Handle fatal errors on shutdown.
- register() : void
- Register all error handlers.
- logToDatabase() : void
- Log error to the database error_logs table.
- notify() : void
- Send error notification email.
- severityToString() : string
- Convert PHP error severity to human-readable string.
Properties
$errorEmail
private
static string|null
$errorEmail
= \null
Email address for error notifications
Methods
handleError()
Handle PHP errors (warnings, notices, etc.).
public
static handleError(int $severity, string $message, string $file, int $line) : bool
Parameters
- $severity : int
-
Error severity level
- $message : string
-
Error message
- $file : string
-
File where error occurred
- $line : int
-
Line number
Return values
boolhandleException()
Handle uncaught exceptions.
public
static handleException(Throwable $e) : void
Parameters
- $e : Throwable
-
The uncaught exception
handleShutdown()
Handle fatal errors on shutdown.
public
static handleShutdown() : void
register()
Register all error handlers.
public
static register() : void
logToDatabase()
Log error to the database error_logs table.
private
static logToDatabase(string $type, string $message, string $file, int $line, string|null $trace) : void
Parameters
- $type : string
-
Error type/class
- $message : string
-
Error message
- $file : string
-
File path
- $line : int
-
Line number
- $trace : string|null
-
Stack trace
notify()
Send error notification email.
private
static notify(string $type, string $message, string $file, int $line[, string|null $trace = null ]) : void
Parameters
- $type : string
-
Error type/class
- $message : string
-
Error message
- $file : string
-
File path
- $line : int
-
Line number
- $trace : string|null = null
-
Stack trace
severityToString()
Convert PHP error severity to human-readable string.
private
static severityToString(int $severity) : string
Parameters
- $severity : int
-
Error severity constant