|
| 1 | +# Configuration |
| 2 | + |
| 3 | +Register `dot-errorhandler` in you project by adding `Dot\ErrorHandler\ConfigProvider::class` to your configuration aggregator (to `config/config.php` for example), |
| 4 | +and add `\Dot\ErrorHandler\ErrorHandlerInterface::class` (to `config/pipeline.php` for example) **as the outermost layer of the middleware** to catch all Exceptions |
| 5 | + |
| 6 | +- Configure the error handler as shown below |
| 7 | + |
| 8 | +config/autoload/error-handling.global.php |
| 9 | + |
| 10 | +```php |
| 11 | +<?php |
| 12 | + |
| 13 | +use Dot\ErrorHandler\ErrorHandlerInterface; |
| 14 | +use Dot\ErrorHandler\LogErrorHandler; |
| 15 | +use Dot\ErrorHandler\ErrorHandler; |
| 16 | + |
| 17 | +return [ |
| 18 | + 'dependencies' => [ |
| 19 | + 'aliases' => [ |
| 20 | + ErrorHandlerInterface::class => LogErrorHandler::class, |
| 21 | + ] |
| 22 | + |
| 23 | + ], |
| 24 | + 'dot-errorhandler' => [ |
| 25 | + 'loggerEnabled' => true, |
| 26 | + 'logger' => 'dot-log.default_logger' |
| 27 | + ] |
| 28 | +]; |
| 29 | +``` |
| 30 | + |
| 31 | +A configuration example for the default logger can be found in `config/log.global.php.dist`. |
| 32 | + |
| 33 | +When declaring the `ErrorHandlerInterface` alias you can choose whether to log or not: |
| 34 | + |
| 35 | +- for the simple Zend Expressive handler user `ErrorHandler` |
| 36 | +- for logging use `LogErrorHandler` |
| 37 | + |
| 38 | +The class `Dot\ErrorHandler\ErrorHandler` is the same as the Zend Expressive error handling class |
| 39 | +the only difference being the removal of the `final` statement for making extension possible. |
| 40 | + |
| 41 | +The class `Dot\ErrorHandler\LogErrorHandler` is `Dot\ErrorHandler\ErrorHandler` with |
| 42 | +added logging support. |
| 43 | + |
| 44 | +As a note: both `LogErrorHandler` and `ErrorHandler` have factories declared in the |
| 45 | +package's `ConfigProvider`. If you need a custom ErrorHandler it must have a factory |
| 46 | +declared in the config, as in the example. |
| 47 | + |
| 48 | +Example: |
| 49 | + |
| 50 | +```php |
| 51 | +<?php |
| 52 | + |
| 53 | +use Dot\ErrorHandler\ErrorHandlerInterface; |
| 54 | +use Custom\MyErrorHandler; |
| 55 | +use Custom\MyErrorHandlerFactory; |
| 56 | + |
| 57 | + |
| 58 | +return [ |
| 59 | + 'dependencies' => [ |
| 60 | + 'factories' => [ |
| 61 | + MyErrorHandler::class => MyCustomHandlerFactory::class, |
| 62 | + ], |
| 63 | + |
| 64 | + 'aliases' => [ |
| 65 | + ErrorHandlerInterface::class => MyErrorHandler::class, |
| 66 | + ] |
| 67 | + |
| 68 | + ], |
| 69 | + 'dot-errorhandler' => [ |
| 70 | + 'loggerEnabled' => true, |
| 71 | + 'logger' => 'dot-log.default_logger' |
| 72 | + ] |
| 73 | +]; |
| 74 | +``` |
| 75 | + |
| 76 | +Config examples can be found in this project's `config` directory. |
0 commit comments