Skip to content
This repository was archived by the owner on Jun 20, 2025. It is now read-only.

confetticode/error-handler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A great unified error handler for PHP

Installation

Install confetticode/error-handler as a Composer dependency in your project.

composer require confetticode/error-handler

Usage

Create a new instance of the ErrorHandler class. By default, HtmlDisplayer will be initialized. This will display an error html page with status code, message and short description.

$errors = new \Confetti\ErrorHandler\ErrorHandler();

Register the $errors instance as the global error handler by doing some logic with set_error_handler, set_exception_handler and register_shutdown_function. Then, any uncaught errors/exceptions will be handled.

$errors->register();

You can change displayer by calling the setDisplayer method.

// Natively available.
$errors->setDisplayer(new \ConfetiCode\ErrorHandler\SymfonyDisplayer);

// To use IgnitionDisplayer, you have to install "spatie/ignition".
$errors->setDisplayer(new \ConfetiCode\ErrorHandler\IgnitionDisplayer);

Integrate with monolog/monolog, eg: writing logs into files.

composer require monolog/monolog
$logger = new \Monolog\Logger('testing');

$logger->setHandlers([
    new \Monolog\Handler\StreamHandler(__DIR__.'/log.txt'),
]);

$reporter = new \ConfettiCode\ErrorHandler\LogReporter($logger);

$errors->setReporter($reporter);

You may try out error.php file for a quick overview.

License

The confetticode/error-handler package is licensed under the MIT license.

About

A great unified error handler for PHP

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages