xervice/exception-handler

2.0.0 2018-08-27 10:21 UTC

This package is auto-updated.

Last update: 2024-03-29 03:07:06 UTC


README

Build Status Scrutinizer Code Quality Code Coverage

Installation

composer require xervice/exception-handler

Configuration

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
        ];
    }
}

Usage

Also you can parse your own exception by using the Facade:

$exceptionHandlerFacade->handleException($exception);

This will loop all defined ExceptionHandler with the given exception.