composer require airbrake/phpbrake
// Create new Notifier instance.
$notifier = new \Airbrake\Notifier(array(
'projectId' => 12345, // FIX ME
'projectKey' => 'abcdefg', // FIX ME
));
// Set global notifier instance.
\Airbrake\Instance::set($notifier);
// Register error and exception handlers.
$handler = new \Airbrake\ErrorHandler($notifier);
$handler->register();
// Somewhere in the app...
try {
throw new Exception('hello from phpbrake');
} catch(Exception $e) {
\Airbrake\Instance::notify($e);
}
Notifier API constists of 4 methods:
buildNotice
- builds Airbrake notice.sendNotice
- sends notice to Airbrake.notify
- shortcut forbuildNotice
andsendNotice
.addFilter
- adds filter that can modify and/or filter notices.
$notifier->addFilter(function ($notice) {
$notice['context']['environment'] = 'production';
return $notice;
});
$notifier->addFilter(function ($notice) {
if (isset($notice['params']['password'])) {
$notice['params']['password'] = 'FILTERED';
}
return $notice;
});
$notifier->addFilter(function ($notice) {
if ($notice['errors'][0]['type'] == 'MyExceptionClass') {
// Ignore this exception.
return null;
}
return $notice;
});
Notifier can handle PHP errors, uncatched exceptions and shutdown. You can register appropriate handlers using following code:
$handler = new \Airbrake\ErrorHandler($notifier);
$handler->register();
Under the hood $handler->register
does following:
set_error_handler(array($this, 'onError'), error_reporting());
set_exception_handler(array($this, 'onException'));
register_shutdown_function(array($this, 'onShutdown'));
$log = new \Monolog\Logger('billing');
$log->pushHandler(new \Airbrake\MonologHandler($notifier));
$log->addError('charge failed', array('client_id' => 123));
composer install
bin/phpunit
composer require phpdocumentor/phpdocumentor
bin/phpdoc -d src
firefox output/index.html