Skip to content
This repository was archived by the owner on Dec 7, 2019. It is now read-only.

ExceptionHandler::attachListener(callable $listener) : void added#47

Open
vaclavvanik wants to merge 1 commit intozfcampus:developfrom
vaclavvanik:feature/exception-handler-listeners
Open

ExceptionHandler::attachListener(callable $listener) : void added#47
vaclavvanik wants to merge 1 commit intozfcampus:developfrom
vaclavvanik:feature/exception-handler-listeners

Conversation

@vaclavvanik
Copy link

As in Zend\Stratigility\Middleware\ErrorHandler I added attachListener method to ExceptionHandler. Listeners are triggered when an exception is caught and provide ability to log exception.

Attach listeners using ExceptionHandler::attachListener():

$exceptionHandler->attachListener(function (Throwable $throwable) use ($logger) {
    $message = sprintf(
        '[%s] %s',
        date('Y-m-d H:i:s'),
        $throwable->getMessage()
    );
    $logger->error($message);
});

Tests are added but I don't know how to test triggering listners because exception handler calls php exit. :-/

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant