2017 © Pedro Peláez
 

library booboo

Provides an error handler for PHP that can execute a stack of handlers for various purposes.

image

league/booboo

Provides an error handler for PHP that can execute a stack of handlers for various purposes.

  • Wednesday, December 13, 2017
  • by alexbilbie
  • Repository
  • 20 Watchers
  • 301 Stars
  • 162,548 Installations
  • PHP
  • 15 Dependents
  • 1 Suggesters
  • 23 Forks
  • 6 Open issues
  • 10 Versions
  • 2 % Grown

The README.md

BooBoo

Quality

Build Status Code Climate Test Coverage, (*1)

Purpose

An error handler for PHP that allows for the execution of handlers and formatters for viewing and managing errors in development and production. Because we all make mistakes., (*2)

Installation

This library requires PHP 5.4 or later. One test is skipped against HHVM, but all others pass. BooBoo will support PHP 7 in a future release., (*3)

It is recommended that you install this library using Composer., (*4)

$ composer require league/booboo

BooBoo is compliant with PSR-1, PSR-2, PSR-3 and PSR-4. If you notice compliance oversights, please send a patch via pull request., (*5)

Dependencies

BooBoo relies upon and requires the following dependencies:, (*6)

  • psr/log - A PSR-3 compliant interface for logging.

No other dependencies are required. The maintainer recommends installing monolog for logging., (*7)

Advantages Over Existing Solutions

BooBoo is designed to help make development easier while providing an integrated solution that can be deployed to your production environment. BooBoo offers the following advantages:, (*8)

Errors are non-blocking by default

Some solutions throw exceptions for all errors, causing every notice to become a fatal error. BooBoo doesn't do this. Rather than raise an exception for non-fatal errors, we display the error to you in a way that makes sense and lets the program continue running. An E_NOTICE shouldn't become an exception., (*9)

The Runner object offers a method for forcing all errors to be blocking, should you wish to throw exceptions for more minor errors. This is turned off by default., (*10)

BooBoo won't end up in your stack trace

Because we don't throw an exception by default, we don't generate a stack trace for minor errors. This means BooBoo won't show up in your logs, and when it handles an exception generated elsewhere, it isn't appended there, either., (*11)

BooBoo is built for logging

This solution is designed with logging in mind, so that you can plug and play a PSR-3 compliant logging solution in and go. BooBoo is sensitive enough to log errors, warnings and notices as such; exceptions are logged as critical, and E_STRICT/E_DEPRECATED warnings are logged as info. Handlers run even if formatting is disabled, so your logging will always be on, even in production., (*12)

BooBoo is designed for extension

We can't possibly think through all your use cases, but we know you can. That's why we use standard interfaces to make it easy to extend and enhance the BooBoo functionality. (We also love pull requests; please share your innovations!), (*13)

BooBoo is actively maintained

PHP is changing every year, and BooBoo will change along with it., (*14)

Getting Started

Instantiation

The main object that you need to instantiate is League\BooBoo\BooBoo. This object takes care of setting the error handler, as well as handling errors and exceptions. It takes optional arguments during construction for handlers and formatters., (*15)

<?php

$booboo = new League\BooBoo\BooBoo();
$booboo->register(); // Registers the handlers

It's very important to call BooBoo::register() or the object won't register itself as PHP's error handler., (*16)

Formatters are very important!

When you're developing, you want to view errors in the browser. In order to do this, you must provide a formatter. Without a formatter, the system won't intelligently know how to display the errors. As a result, the Runner will throw an exception and won't register the error handlers., (*17)

The library ships with four formatters for your convenience:, (*18)

  • HtmlFormatter - Formats errors just like PHP's error formatting.
  • HtmlTableFormatter - Formats errors and exceptions similar to Xdebug, wth a full stack trace, even for errors.
  • JsonFormatter - Perfect for displaying errors to an API.
  • CommandLineFormatter - Working with the command line? This will produce pretty command-line errors.
  • NullFormatter - This formatter simply silences all errors. You can pass this when display_errors = Off. Adding a formatter is easy:
<?php

$booboo->pushFormatter(new League\BooBoo\Formatter\HtmlFormatter());

Controlling which formatter does the formatting

There may be times that you want certain formatters to handle the formatting for particular errors, and others to handle the formatting for other error types. Formatters support this., (*19)

For example, if you want all errors of warning or higher to show in the browser, but errors that are below this level to be ignored, you can configure the formatters to handle this scenario as such:, (*20)

<?php

$html = new League\BooBoo\Formatter\HtmlFormatter();
$null = new League\BooBoo\Formatter\NullFormatter();

$html->setErrorLimit(E_ERROR | E_WARNING | E_USER_ERROR | E_USER_WARNING);
$null->setErrorLimit(E_ALL);

$booboo->pushFormatter($null);
$booboo->pushFormatter($html);

Formatters and handlers are a stack

Formatters and handlers are treated as a stack. This means that the last item in will be the first item out. This is very important when dealing with formatters that only handle certain errors!, (*21)

For example, in the example above, we have one formatter limited to errors and warnings, and the other formatting all error types. If we insert the HTML handler first, it will be run last; this would cause the NullFormatter to format all errors, and we would get no output., (*22)

Handlers

Regardless of whether or not you want to format the error (or even output it to the screen), you may want to handle it in some way, such as logging it. BooBoo provides a way to handle errors, and provides a built-in PSR-3 compatible logging handler., (*23)

You can implement the HandlerInterface to create your own handlers. Handlers are run regardless of whether or not display_errors is true. Unlike formatters, you cannot direct handlers to ignore certain errors; it's assumed that you can handle this with the services that handlers work through., (*24)

Documentation

Check out the documentation here, (*25)

Security

If you have identified a security issue, please email brandon@brandonsavage.net directly. Do not file an issue as they are public!, (*26)

The Versions

13/12 2017

dev-master

9999999-dev

Provides an error handler for PHP that can execute a stack of handlers for various purposes.

  Sources   Download

MIT

The Requires

 

The Development Requires

01/09 2017

2.0

2.0.0.0

Provides an error handler for PHP that can execute a stack of handlers for various purposes.

  Sources   Download

MIT

The Requires

 

The Development Requires

25/02 2015

1.0.0

1.0.0.0

Provides an error handler for PHP that can execute a stack of handlers for various purposes.

  Sources   Download

MIT

The Requires

 

The Development Requires

31/01 2015

0.4.2

0.4.2.0

Provides an error handler for PHP that can execute a stack of handlers for various purposes.

  Sources   Download

MIT

The Requires

 

The Development Requires

22/01 2015

0.4.1

0.4.1.0

Provides an error handler for PHP that can execute a stack of handlers for various purposes.

  Sources   Download

MIT

The Requires

 

The Development Requires

09/01 2015

0.4.0

0.4.0.0

Provides an error handler for PHP that can execute a stack of handlers for various purposes.

  Sources   Download

MIT

The Requires

 

The Development Requires

09/01 2015

0.3.1

0.3.1.0

Provides an error handler for PHP that can execute a stack of handlers for various purposes.

  Sources   Download

MIT

The Requires

 

The Development Requires

09/01 2015

0.3.0

0.3.0.0

Provides an error handler for PHP that can execute a stack of handlers for various purposes.

  Sources   Download

MIT

The Requires

 

The Development Requires

06/12 2014

0.2.0

0.2.0.0

Provides an error handler for PHP that can execute a stack of handlers for various purposes.

  Sources   Download

MIT

The Requires

 

The Development Requires

05/12 2014

0.1.0

0.1.0.0

Provides an error handler for PHP that can execute a stack of handlers for various purposes.

  Sources   Download

MIT

The Requires

 

The Development Requires