Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

dotkernel/dot-errorhandler

Open more actions menu

Repository files navigation

dot-errorhandler

dot-errorhandler is Dotkernel's PSR-15 compliant error handler.

Documentation

Documentation is available at: https://docs.dotkernel.org/dot-errorhandler/

Badges

OSS Lifecycle PHP from Packagist (specify version)

GitHub issues GitHub forks GitHub stars GitHub license

Build Static codecov PHPStan

Adding the error handler

  • Add the composer package:
composer require dotkernel/dot-errorhandler
  • Add the config provider:
    • in config/config.php add \Dot\ErrorHandler\ConfigProvider
    • in config/pipeline.php add \Dot\ErrorHandler\ErrorHandlerInterface::class
      • the interface is used as an alias to keep all error handling related configurations in one file

If you need other error handlers, you should place them before dot-errorhandler in the pipeline; else it will not be able to catch errors. We recommend using just one error handler unless you have an error-specific handler.

  • Configure the error handler as shown below.

In config/autoload/error-handling.global.php:

<?php

use Dot\ErrorHandler\ErrorHandlerInterface;
use Dot\ErrorHandler\LogErrorHandler;
use Dot\ErrorHandler\ErrorHandler;

return [
    'dependencies' => [
        'aliases' => [
            ErrorHandlerInterface::class => LogErrorHandler::class,
        ]

    ],
    'dot-errorhandler' => [
        'loggerEnabled' => true,
        'logger' => 'dot-log.default_logger'
    ]
];

A configuration example for the default logger can be found in config/log.global.php.dist.

When configuring the error handler in your application, you can choose between two classes:

  • Dot\ErrorHandler\LogErrorHandler: for logging and displaying errors
  • Dot\ErrorHandler\ErrorHandler: for displaying errors only

Both LogErrorHandler and ErrorHandler have factories declared in the package's ConfigProvider. If you need a custom ErrorHandler, it must have a factory declared in the config, as in the below example:

<?php

use Dot\ErrorHandler\ErrorHandlerInterface;
use Custom\MyErrorHandler;
use Custom\MyErrorHandlerFactory;

return [
    'dependencies' => [
        'factories' => [
            MyErrorHandler::class => MyCustomHandlerFactory::class,
        ],
        'aliases' => [
            ErrorHandlerInterface::class => MyErrorHandler::class,
        ]
    ],
    'dot-errorhandler' => [
        'loggerEnabled' => true,
        'logger' => 'dot-log.default_logger',
    ]
];

Config examples can be found in this project's config directory.

About

Logging Error Handler for Dotkernel

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 7

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.