2017 © Pedro Peláez
 

library php-airbrake

A PHP 5.3 library for sending errors to the Airbrake.io service.

image

ibrows/php-airbrake

A PHP 5.3 library for sending errors to the Airbrake.io service.

  • Friday, January 8, 2016
  • by ibrows
  • Repository
  • 14 Watchers
  • 0 Stars
  • 9,523 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 49 Forks
  • 0 Open issues
  • 15 Versions
  • 2 % Grown

The README.md

PHP Airbrake

Build Status HHVM Status, (*1)

A PHP module to make use of the Airbrake API for storing error messages., (*2)

Installation

The best way to install the library is by using Composer. Add the following to composer.json in the root of your project:, (*3)

``` javascript { "require": { "dbtlr/php-airbrake": "~1.1" } }, (*4)


Then, on the command line: ``` bash curl -s http://getcomposer.org/installer | php php composer.phar install

Use the generated vendor/autoload.php file to autoload the library classes., (*5)

Exception Handler Example

The preferred method for this to be used is via error and exception handlers, so that you do not have to manually call the configuration and client class every time. This is simply done by calling up the built in error handler and passing in your API key to its start() method like so:, (*6)

<?php
require_once 'vendor/autoload.php';
Airbrake\EventHandler::start('[your api key]');

Optionally, you may pass a second parameter as TRUE to the start() method, in order to enable the logging of warning level messages as well. This is disabled by default, as it may considered too noisy, depending on the quality of the code base. There is also a third options array that may be passed, which will load many of the more common configuration options. These options are located below., (*7)

Basic Usage Example

If calling the class directly and not through an exception handler, it would be done like this:, (*8)

<?php
require_once 'vendor/autoload.php';

$apiKey  = '[your api key]'; // This is required
$options = array(); // This is optional

$config = new Airbrake\Configuration($apiKey, $options);
$client = new Airbrake\Client($config);

// Send just an error message
$client->notifyOnError('My error message');

// Send an exception that may have been generated or caught.
try {
    throw new Exception('This is my exception');

} catch (Exception $exception) {
    $client->notifyOnException($exception);
}

The options array may be filled with data from the Configuration Options section, if you would like to override some of the default options. Otherwise, it can be ignored., (*9)

Configuration Options

  • timeout - Defaults to 2, this is how long the service will wait before giving up. This should be set to a sane limit, so as to avoid excessive page times in the event of a failure.
  • environmentName - Defaults to 'production'. This can be changed to match the environment that you are working, which will help prevent messy logs, filled with non-production problems.
  • serverData - This defaults to the $_SERVER array, but can be overridden with any array of data.
  • getData - Defaults to the $_GET array
  • postData - Defaults to the $_POST array
  • sessionData - Defaults to the $_SESSION array
  • component - This is the name of the component or controller that is running.
  • action - The name of the action that was called.
  • projectRoot - Defaults to the Document Root. May need to change based on the context of your application.
  • url - The main URL that was requested.
  • hostname - The hostname that was requested.
  • secure - Optional - Boolean that allows you to define if you want to hit the secure Airbrake endpoint.
  • errorReportingLevel - Optional - functions the same way as the error_reporting php.ini setting (this is applied on top of show warnings parameter on the EventHandler::start method)
  • proxyHost - An optional HTTP proxy host through which all connections will be sent.
  • proxyPort - The HTTP proxy port (required only if proxyHost is supplied). Defaults to 80.
  • proxyUser - The HTTP proxy username (optional even if proxyHost is supplied).
  • proxyPass - The HTTP proxy password (required only if proxyUser is supplied).

Filters

You can add filters to the request data that will be sent to your Airbrake server by calling the addFilter or addFilters methods. The default is to define a filter via the form name attribute. For example, if you had a form like this:, (*10)



You could filter out all of the user details with the code:, (*11)

<?php

$config = Airbrake\EventHandler::getClient()->getConfiguration();
$config->addFilter('user');

Or just the password by using the filter, (*12)

<?php

$config = Airbrake\EventHandler::getClient()->getConfiguration();
$config->addFilter('user[password]');

You can also define your own filter classes by implementing the Airbrake\Filter\FilterInterface interface., (*13)

<?php

class MyFilter implements Airbrake\Filter\FilterInterface
{
  public function filter(&$post_data)
  {
    if (array_key_exists('some_key', $post_data)){
      unset($post_data['some_key']);
    }
  }
}
$config = Airbrake\EventHandler::getClient()->getConfiguration();
$config->addFilter(new MyFilter());

Error/Exception Filters

You can also define your own filters for filtering PHP Errors. If, for example, you want to have strict warnings on, but have some legacy subsystem that generates a lot of strict warnings, you can do the following:, (*14)

<?php

class MyErrorFilter implements Airbrake\EventFilter\Error\FilterInterface
{
  public function shouldSendError($type, $message, $file, $line, $context = null)
  {
    if ($type == E_STRICT && preg_match('/LegacyController.php/', $file)){
      return false;
    }
  }
}

$airbrake = Airbrake\EventHandler::start();
$airbrake->addErrorFilter(new MyErrorFilter());

You can do the same thing for uncaught exceptions - say your project throws ACL exceptions that bubble up to Airbrake, you can filter them out like this:, (*15)

<?php

class MyExceptionFilter implements Airbrake\EventFilter\Exception\FilterInterface
{
  public function shouldSendException($exception)
  {
    return !($exception instanceof AclException);
  }
}

$airbrake = Airbrake\EventHandler::start();
$airbrake->addExceptionFilter(new MyExceptionFilter());

Contributing

A few things to note, if you want to add features. First off, I love pull requests. If you have a feature that you wish this had, please feel free to add it and submit it to me. I'll try to be as responsive as possible., (*16)

Somethings to know:, (*17)

  • Please maintain the PSR-2 coding standard. For reference as to what this is, check the PSR-2 standard page.
  • This plugin should maintain compatibility with PHP 5.3+. I know, PHP 5.3 is end of life, however many people are still forced to use it regardless.
  • Travis runs automatically for pull requests, if travis doesn't pass, then I won't merge.

How to check

You simply need 2 commands to verify things are working as expected., (*18)

1) PHPUnit, (*19)

``` bash vendor/bin/phpunit, (*20)


2) PHPCS ``` bash vendor/bin/phpcs --standard=PSR2 src

As long as these pass, you should be golden. The one catch is that Travis will check multiple versions of PHP, so if you use syntax specific to PHP 5.4+, then you may see a failure., (*21)

The Versions

08/01 2016

dev-master

9999999-dev https://github.com/dbtlr/php-airbrake

A PHP 5.3 library for sending errors to the Airbrake.io service.

  Sources   Download

MIT

The Development Requires

logging errors airbrake exceptions

08/01 2016

1.1.5

1.1.5.0 https://github.com/dbtlr/php-airbrake

A PHP 5.3 library for sending errors to the Airbrake.io service.

  Sources   Download

MIT

The Development Requires

logging errors airbrake exceptions

25/08 2015

1.1.4

1.1.4.0 https://github.com/dbtlr/php-airbrake

A PHP 5.3 library for sending errors to the Airbrake.io service.

  Sources   Download

MIT

The Development Requires

logging errors airbrake exceptions

30/04 2015

v1.1.3

1.1.3.0 https://github.com/dbtlr/php-airbrake

A PHP 5.3 library for sending errors to the Airbrake.io service.

  Sources   Download

MIT

The Development Requires

logging errors airbrake exceptions

18/04 2015

v1.1.2

1.1.2.0 https://github.com/dbtlr/php-airbrake

A PHP 5.3 library for sending errors to the Airbrake.io service.

  Sources   Download

MIT

The Development Requires

logging errors airbrake exceptions

13/02 2015

1.1.1

1.1.1.0 https://github.com/dbtlr/php-airbrake

A PHP 5.3 library for sending errors to the Airbrake.io service.

  Sources   Download

MIT

The Development Requires

logging errors airbrake exceptions

13/02 2015

v1.1.0

1.1.0.0 https://github.com/dbtlr/php-airbrake

A PHP 5.3 library for sending errors to the Airbrake.io service.

  Sources   Download

MIT

The Requires

 

logging errors airbrake exceptions

26/01 2015

1.0.6

1.0.6.0 https://github.com/dbtlr/php-airbrake

A PHP 5.3 library for sending errors to the Airbrake.io service.

  Sources   Download

MIT

The Requires

  • php >=5.3.1

 

logging errors airbrake exceptions

12/11 2014

1.0.5

1.0.5.0 https://github.com/dbtlr/php-airbrake

A PHP 5.3 library for sending errors to the Airbrake.io service.

  Sources   Download

MIT

The Requires

  • php >=5.3.1

 

logging errors airbrake exceptions

12/11 2014

1.0.4

1.0.4.0 https://github.com/dbtlr/php-airbrake

A PHP 5.3 library for sending errors to the Airbrake.io service.

  Sources   Download

MIT

The Requires

  • php >=5.3.1

 

logging errors airbrake exceptions

04/11 2014

1.0.3

1.0.3.0 https://github.com/dbtlr/php-airbrake

A PHP 5.3 library for sending errors to the Airbrake.io service.

  Sources   Download

MIT

The Requires

  • php >=5.3.1

 

logging errors airbrake exceptions

25/09 2014

1.1.0rc1

1.1.0.0-RC1 https://github.com/dbtlr/php-airbrake

A PHP 5.3 library for sending errors to the Airbrake.io service.

  Sources   Download

MIT

The Requires

 

logging errors airbrake exceptions

25/09 2014

1.0.0

1.0.0.0 https://github.com/dbtlr/php-airbrake

A PHP 5.3 library for sending errors to the Airbrake.io service.

  Sources   Download

MIT

The Requires

  • php >=5.3.1

 

logging errors airbrake exceptions

05/07 2013

1.0.1

1.0.1.0 https://github.com/dbtlr/php-airbrake

A PHP 5.3 library for sending errors to the Airbrake.io service.

  Sources   Download

MIT

The Requires

  • php >=5.3.1

 

logging errors airbrake exceptions

05/07 2013

1.0.2

1.0.2.0 https://github.com/dbtlr/php-airbrake

A PHP 5.3 library for sending errors to the Airbrake.io service.

  Sources   Download

MIT

The Requires

  • php >=5.3.1

 

logging errors airbrake exceptions