PHPackages                             marcoazn89/booboo - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Debugging &amp; Profiling](/categories/debugging)
4. /
5. marcoazn89/booboo

ActiveLibrary[Debugging &amp; Profiling](/categories/debugging)

marcoazn89/booboo
=================

A framework to handle your production boo-boo's

v2.3.0(7y ago)028.2k↓50%11MITPHPPHP &gt;=5.3.0

Since Mar 17Pushed 7y ago1 watchersCompare

[ Source](https://github.com/marcoazn89/booboo)[ Packagist](https://packagist.org/packages/marcoazn89/booboo)[ Docs](https://github.com/marcoazn89/booboo)[ RSS](/packages/marcoazn89-booboo/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (2)Versions (11)Used By (1)

Install via Composer
--------------------

[](#install-via-composer)

```
composer require marcoazn89/booboo:dev-master

```

Features
--------

[](#features)

- Dynamic error templates for production errors
- Content negotiation to show the right error format (HTML, JSON, XML, etc)
- PSR-3 compliant (set your own logger)
- PSR-7 compliant (pass a response object with headers and status code)

Run BooBoo
----------

[](#run-booboo)

This is something you want to do at the begining of your application.

```
require '../vendor/autoload.php';

use Exception\BooBoo;

// This is a simple set up
BooBoo::setUp();
```

The setUp() method takes 4 parameters:

1. $logger: BooBoo will use error\_log by default. If you want to use your own you can pass a psr2 logger compliant like [`Monolog`](https://github.com/Seldaek/monolog).
2. $traceAlwaysOn: Turn of or off stack traces. By default they are turned off. You can always turn it on or off later when you throw an exception, but any other regular exception or php error will use the setting defined at the set up
3. $lastAction: This is a callback that will be ran before exiting the application upon encountering an error
4. $ignore: This is an array containing php error constants that you want to ignore.

```
// A more complex set up
BooBoo::setUp(
	$logger,
	true,
	function() { $textMessageService->send('Hey something broke');},
	[E_NOTICE, E_DEPRECATED]
);
```

What happens when an error occurs?
----------------------------------

[](#what-happens-when-an-error-occurs)

```
require '../vendor/autoload.php';

use Exception\BooBoo;

BooBoo::setUp();

// This causes a fatal error
$random->error();
```

[![BooBoo!](https://camo.githubusercontent.com/c6de3a9b44990d837a4eff24a324bdeca8a4ecf3e2c2e559491b58a7aff29ac3/687474703a2f2f692e696d6775722e636f6d2f4f4749514469502e706e673f31)](https://camo.githubusercontent.com/c6de3a9b44990d837a4eff24a324bdeca8a4ecf3e2c2e559491b58a7aff29ac3/687474703a2f2f692e696d6775722e636f6d2f4f4749514469502e706e673f31)[![BooBoo!](https://camo.githubusercontent.com/97f072b87437f2a98ddb3067ec0f9820426dd5db05de660bf653d8c76ef473cc/687474703a2f2f692e696d6775722e636f6d2f5458626f4c61502e706e67)](https://camo.githubusercontent.com/97f072b87437f2a98ddb3067ec0f9820426dd5db05de660bf653d8c76ef473cc/687474703a2f2f692e696d6775722e636f6d2f5458626f4c61502e706e67)

BooBoo pays attention to Accept headers
---------------------------------------

[](#booboo-pays-attention-to-accept-headers)

Client requesting JSON

[![BooBoo!](https://camo.githubusercontent.com/a15cd66459db48959003501e2b4d43ba1bb894512ec74541ba8b513bafbee2ad/687474703a2f2f692e696d6775722e636f6d2f32316b525a4c702e706e67)](https://camo.githubusercontent.com/a15cd66459db48959003501e2b4d43ba1bb894512ec74541ba8b513bafbee2ad/687474703a2f2f692e696d6775722e636f6d2f32316b525a4c702e706e67)

Client requesting XML

[![BooBoo!](https://camo.githubusercontent.com/a901d53f25ab58199eb07a43941b2b275d32400bdff9fc86051f34c42f166364/687474703a2f2f692e696d6775722e636f6d2f79633071774b702e706e67)](https://camo.githubusercontent.com/a901d53f25ab58199eb07a43941b2b275d32400bdff9fc86051f34c42f166364/687474703a2f2f692e696d6775722e636f6d2f79633071774b702e706e67)

Creating exceptions and templates
---------------------------------

[](#creating-exceptions-and-templates)

1. Simply extend `\Exception\BooBoo` and implement the two abstract methods

```
class DatabaseException extends \Exception\BooBoo
{
	// It's good practice to define constants so that your exception messages are consistant
	const NOT_FOUND = 'Data requested was not found';

	/**
	 * This will be what's shown in the logs
	 * Example: [21-Mar-2016 05:58:27 Europe/Berlin] : Something bad happened
	 */
	protected function getTag()
	{
		return 'DbException';
	}

	/**
	 * Return an array that defines your error template location or strings.
	 * For any template that is not defined, BooBoo will use its default templates.
	 * There are 4 templates currently supported: html, text, xml, json
	 */
	protected function getTemplates()
	{
		return [
			'html' => "Something went really WRONG!",
			'json' => __DIR__ . '/json.php'
		];
	}
}
```

2. Templates get the following varibles injected:

- $response: The psr7 response object
- $message: The message that was defined for the template or null if none was provided
- $data: Any data that was passed to the template or null if none was provided

```
