v-six / silex-raven
A Silex Service Provider for Raven
Installs: 7 463
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=5.3.0
- pimple/pimple: ~1.0
- raven/raven: ~0.8
Requires (Dev)
- phpunit/phpunit: ~3.7
- silex/silex: ~1.2
This package is not auto-updated.
Last update: 2024-12-21 15:49:49 UTC
README
A basic Silex service provider for PHP client for Sentry : getsentry/raven-php.
Installation
The recommended way to install silex-raven is through Composer. Just create a composer.json file and run the php composer.phar install command to install it:
{ "require": { "v-six/silex-raven": "0.1.*" } }
Alternatively, you can download the silex-raven.zip file and extract it.
Usage
$app->register(new SilexRaven\RavenServiceProvider(), array( 'raven.dsn' => 'http://public:secret@example.com/1', 'raven.options' => array( 'logger' => 'my-logger-name' // Set custom logger name ) 'raven.handle' => array( 'exceptions' => false, // Disable exceptions handler 'errors' => true, // Enable errors handler 'fatal_errors' => true, // Enable fatal_errors handler ) ) );
If necessary, set your own options in raven.options
(see Raven documentation).
All handlers are registered by default, you can disable them by setting corresponding configuration input to false in raven.handle
.
Custom
You can easily capture an error or an exception with the following :
// Capture an error $app['raven']->captureMessage('Oops !'); // Capture an exception $app['raven']->captureException(new \Exception('Oops !')); // Capture an exception with additional debug data $app['raven']->captureException(new \Exception('Oops !'), array( 'extra' => array( 'php_version' => phpversion() ), ) );
Obviously you can also provide custom request context :
// Bind the logged in user $app['raven']->user_context(array('email' => 'foo@example.com')); // Tag the request with something interesting $app['raven']->tags_context(array('interesting' => 'yes')); // Provide a bit of additional context $app['raven']->extra_context(array('happiness' => 'very')); // Clean all previously provided context $app['raven']->context->clear();
Example
Here is a full example coupled with Silex error handler (see Silex error handlers documentation) :
$app = new Silex\Application(); $app->register( new \SilexRaven\RavenServiceProvider(), ['raven.dsn' => 'http://public:secret@example.com/1'] ); $app->error(function (\Exception $e, $code) use($app, $user) { $app['raven']->user_context(array('email' => $user->email)); $app['raven']->captureException($e) $app['raven']->context->clear(); return new Response("There is an error !"); });