PHP code example of struzik-vladislav / php-error-handler

1. Go to this page and download the library: Download struzik-vladislav/php-error-handler library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

struzik-vladislav / php-error-handler example snippets




use Struzik\ErrorHandler\ErrorHandler;
use Struzik\ErrorHandler\Processor\LoggerProcessor;
use Struzik\ErrorHandler\Processor\IntoExceptionProcessor;
use Struzik\ErrorHandler\Exception\ErrorException;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$logger = new Logger('ErrorHandler DEMO');
$logger->pushHandler(new StreamHandler('php://output', Logger::DEBUG));

$errorHandler = new ErrorHandler();
$errorHandler->pushProcessor(new IntoExceptionProcessor())
    ->pushProcessor(new LoggerProcessor($logger));

try {
    $errorHandler->set();
    trigger_error('Dummy error', E_USER_NOTICE);
    $errorHandler->restore();
} catch (ErrorException $e) {
    echo $e;
}

/*
[2017-05-13 21:42:46] ErrorHandler DEMO.NOTICE: Dummy error in /srv/php-error-handler/example.php:21 {"backtrace":"#0 /srv/php-error-handler/src/ErrorHandler.php(39): Struzik\\ErrorHandler\\Processor\\LoggerProcessor->handle(1024, 'Dummy error', '/srv/php-error-...', 21)\n#1 [internal function]: Struzik\\ErrorHandler\\ErrorHandler->handle(1024, 'Dummy error', '/srv/php-error-...', 21, Array)\n#2 /srv/php-error-handler/example.php(21): trigger_error('Dummy error', 1024)\n#3 {main}"} []

Struzik\ErrorHandler\Exception\UserNoticeException: Dummy error in /srv/php-error-handler/example.php:21
Stack trace:
#0 /srv/php-error-handler/src/ErrorHandler.php(39): Struzik\ErrorHandler\Processor\IntoExceptionProcessor->handle(1024, 'Dummy error', '/srv/php-error-...', 21)
#1 [internal function]: Struzik\ErrorHandler\ErrorHandler->handle(1024, 'Dummy error', '/srv/php-error-...', 21, Array)
#2 /srv/php-error-handler/example.php(21): trigger_error('Dummy error', 1024)
*/