Skip to content

Commit 9260463

Browse files
authored
Merge pull request #39 from hackel/custom-abstract-type
Allow overriding abstract type Sentry is bound to in service container.
2 parents e59fa72 + c87af10 commit 9260463

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/Sentry/SentryLaravel/SentryLaravelServiceProvider.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22

33
namespace Sentry\SentryLaravel;
44

5-
use Log;
65
use Illuminate\Support\ServiceProvider;
76

87
class SentryLaravelServiceProvider extends ServiceProvider
98
{
9+
/**
10+
* Abstract type to bind Sentry as in the Service Container.
11+
*
12+
* @var string
13+
*/
14+
public static $abstract = 'sentry';
15+
1016
/**
1117
* Indicates if loading of the provider is deferred.
1218
*
@@ -25,21 +31,21 @@ public function boot()
2531

2632
// Laravel 4.x compatibility
2733
if (version_compare($app::VERSION, '5.0') < 0) {
28-
$this->package('sentry/sentry-laravel', 'sentry');
34+
$this->package('sentry/sentry-laravel', static::$abstract);
2935

3036
$app->error(function (\Exception $e) use ($app) {
31-
$app['sentry']->captureException($e);
37+
$app[static::$abstract]->captureException($e);
3238
});
3339

3440
$app->fatal(function ($e) use ($app) {
35-
$app['sentry']->captureException($e);
41+
$app[static::$abstract]->captureException($e);
3642
});
3743

3844
$this->bindEvents($app);
3945
} else {
4046
// the default configuration file
4147
$this->publishes(array(
42-
__DIR__ . '/config.php' => config_path('sentry.php'),
48+
__DIR__ . '/config.php' => config_path(static::$abstract . '.php'),
4349
), 'config');
4450

4551
$this->bindEvents($app);
@@ -48,7 +54,7 @@ public function boot()
4854

4955
protected function bindEvents($app)
5056
{
51-
$handler = new SentryLaravelEventHandler($app['sentry'], $app['sentry.config']);
57+
$handler = new SentryLaravelEventHandler($app[static::$abstract], $app[static::$abstract . '.config']);
5258
$handler->subscribe($app->events);
5359
}
5460

@@ -59,9 +65,9 @@ protected function bindEvents($app)
5965
*/
6066
public function register()
6167
{
62-
$this->app->singleton('sentry.config', function ($app) {
68+
$this->app->singleton(static::$abstract . '.config', function ($app) {
6369
// sentry::config is Laravel 4.x
64-
$user_config = $app['config']['sentry'] ?: $app['config']['sentry::config'];
70+
$user_config = $app['config'][static::$abstract] ?: $app['config'][static::$abstract . '::config'];
6571

6672
// Make sure we don't crash when we did not publish the config file
6773
if (is_null($user_config)) {
@@ -71,8 +77,8 @@ public function register()
7177
return $user_config;
7278
});
7379

74-
$this->app->singleton('sentry', function ($app) {
75-
$user_config = $app['sentry.config'];
80+
$this->app->singleton(static::$abstract, function ($app) {
81+
$user_config = $app[static::$abstract . '.config'];
7682

7783
$client = SentryLaravel::getClient(array_merge(array(
7884
'environment' => $app->environment(),
@@ -102,6 +108,6 @@ public function register()
102108
*/
103109
public function provides()
104110
{
105-
return array('sentry');
111+
return array(static::$abstract);
106112
}
107113
}

0 commit comments

Comments
 (0)