nicklasos
7/29/2015 - 10:54 AM

getsentry.com silex provider

getsentry.com silex provider

<?php
namespace Plariumed\ErrorHandler;

use Raven_Client;
use Raven_ErrorHandler;
use Silex\Application;
use Silex\ServiceProviderInterface;

class ErrorClientProvider implements ServiceProviderInterface
{
    private $key;
    private $register;

    public function __construct(array $params)
    {
        $this->key = $params['key'];
        $this->register = isset($params['register']) ? $params['register'] : [];
    }

    public function register(Application $app)
    {
        $client = new Raven_Client($this->key);

        $error_handler = new Raven_ErrorHandler($client);

        if (in_array('exception', $this->register)) {
            $error_handler->registerExceptionHandler();
        }

        if (in_array('error', $this->register)) {
            $error_handler->registerErrorHandler();
        }

        if (in_array('shutdown', $this->register)) {
            $error_handler->registerShutdownFunction();
        }

        $app['error.client'] = $app->share(function () use ($client) {
            return $client;
        });
    }

    public function boot(Application $app)
    {
    }
}
<?php
$app->register(new ErrorClientProvider([
    'key' => 'https://***@app.getsentry.com/00000',
    'register' => ['exeption', 'error', 'shutdown'],
]));

$app['error.client']->user_context(array(
    'email' => $user->getEmail()
));