Symfony with Raygun4PHP

Symfony with Raygun4PHP

Step by Step Instructions

Step One: Install with Composer

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: Create the RaygunExceptionListener file

Create a new `RaygunExceptionListener` file at `src/AppBundle/EventListener/RaygunExceptionListener` and add the following content, which will send a exception when the kernal exception event is dispatched.

Make sure you change the apiKey to your Raygun API key.

namespace AppBundle\EventListener;

use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Raygun;

class RaygunExceptionListener

    private $client;

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

    public function onKernelException(GetResponseForExceptionEvent $event)
        // You get the exception object from the received event
        $exception = $event->getException();

Step Three: Register the Event Listener

Open the `app/config/services.yml` file and add the following.

    class: AppBundle\EventListener\RaygunExceptionListener
        - { name: kernel.event_listener, event: kernel.exception }

Further Information

More information about Symfony Events Listeners can be found here.

Documentation missing?

If we don't have documentation about your desired topic, send us a message and we'll create it for you.