GithubHelp home page GithubHelp logo

struzik-vladislav / php-error-handler Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 14 KB

Handling PHP errors in various processors

License: MIT License

PHP 100.00%
php error handler converter exception logger

php-error-handler's Introduction

PHP Error Handler Travis

Handling PHP errors in various processors.

Types of errors that can be handled according to set_error_handler:

  • E_STRICT
  • E_RECOVERABLE_ERROR
  • E_NOTICE
  • E_WARNING
  • E_DEPRECATED
  • E_USER_ERROR
  • E_USER_NOTICE
  • E_USER_WARNING
  • E_USER_DEPRECATED

Processors

ReturnFalseProcessor

The processor for enabling native PHP handler after custom.

LoggerProcessor

The processor for writing to the PSR-3 compatible logger like Monolog.

IntoExceptionProcessor

The processor for converting errors to exceptions. The basic type of throwing exception is Struzik\ErrorHandler\Exception\ErrorException.

Usage

<?php

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)
*/

php-error-handler's People

Contributors

struzik-vladislav avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.