The League of Extraordinary Packages

Our Packages:

Presented by The League of Extraordinary Packages

Getting Started

Using BooBoo

Using Formatters

BooBoo makes use of objects called Formatters to format error messages in a variety of ways. This makes them easy to read during the development process, and permits you to generate a user-facing “friendly” error page in production.

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.

The library ships with several formatters for your convenience:

Registering a formatter is easy:

$runner->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.

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:

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



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!

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.

Error formatting on production systems

The display_errors setting (in php.ini) is generally switched off on production servers, as a security measure, to prevent exposing sensitive information to end users. BooBoo respects this setting: the stack of error formatters will be ignored on production systems.

To designate an error-formatter for use on production systems, use Runner::setErrorPageFormatter() - with display_errors switched off, this special formatter will be used instead of the error formatter stack.

Note that BooBoo does not presently ship with a built-in “friendly” error-formatter.