composer require xervice/exception-handler
You have to add the ExceptionService to your kernel stack.
After that the defined registers will be executed. To define a register you have to overwrite the DependencyProvider:
<?php
namespace App\ExceptionHandler;
use Xervice\ExceptionHandler\ExceptionHandlerDependencyProvider as XerviceExceptionHandlerDependencyProvider;
class ExceptionHandlerDependencyProvider extends XerviceExceptionHandlerDependencyProvider
{
/**
* @return \Xervice\ExceptionHandler\Business\Model\Register\RegisterInterface[]
*/
public function getExceptionRegister(): array
{
return [
new MyExceptionRegister() // implements RegisterInterface
];
}
}You can define the default "ExceptionHandlerRegister". If you use it, you can define own ExceptionHandler. Every ExceptionHandler get automatically exexpected exceptions. You can define your ExceptionHandler also in the Dependency Provider.
<?php
namespace App\ExceptionHandler;
use Xervice\ExceptionHandler\ExceptionHandlerDependencyProvider as XerviceExceptionHandlerDependencyProvider;
class ExceptionHandlerDependencyProvider extends XerviceExceptionHandlerDependencyProvider
{
/**
* @return \Xervice\ExceptionHandler\Business\Model\Handler\ExceptionHandlerInterface[]
*/
public function getExceptionHandler(): array
{
return [
new MyExceptionHandler() // implements ExceptionHandlerInterface
];
}
}Also you can parse your own exception by using the Facade:
$exceptionHandlerFacade->handleException($exception);
This will loop all defined ExceptionHandler with the given exception.
