CodeIgniter

Installation

Step One

If you use a *nix environment, follow the instructions to install Composer. Windows users can run this installer to automatically add it to the path etc.

Inside your project’s root directory create a composer.json file, containing:

{
    "require": {
        "mindscape/raygun4php": "1.*"
    }
}

From your shell run php composer.phar install (*nix) or composer install (Windows). This will download Raygun4PHP and create the appropriate autoload data.

Step Two: Enable Hooks

Inside of /application/config/config.php set enable_hooks to true:

<?php
$config['enable_hooks'] = TRUE;

Step Three: Create the RaygunSetup File

Create a RaygunSetup file at /application/hooks/RaygunSetup.php. This file creates the RaygunClient and sets the error/exception handlers.

Add the following content. Making sure to change the apiKey to your Raygun API key.

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

    class RaygunSetup {
        private $client;

        public function __construct()
        {
            $this->client = new \Raygun4php\RaygunClient("apiKey");
        }

        public function set_exception_handler()
        {
            set_exception_handler( array( $this,'exception_handler' ) );
            set_error_handler( array( $this, "error_handler" ) );
        }

        function exception_handler($exception) {
            $this->client->SendException($exception);
        }

        function error_handler( $errno, $errstr, $errfile, $errline) {
            $this->client->SendError($errno, $errstr, $errfile, $errline);
        }

    }
}

Step Four: Add the hook

In /config/hooks.php enable the hook for the file we just created.

<?php
$hook['pre_controller'][] = array(
    'class'    => 'RaygunSetup',
    'function' => 'set_exception_handler',
    'filename' => 'RaygunSetup.php',
    'filepath' => 'hooks'
);

The provider is open source and available at the Raygun4PHP repository.