Skip to content

Commit 8773168

Browse files
tobz-nzArturMoczulski
authored andcommitted
Tidy up stopping boot/registration
1 parent e850bb0 commit 8773168

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/RollbarServiceProvider.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class RollbarServiceProvider extends ServiceProvider
2020
public function boot()
2121
{
2222
// Don't boot rollbar if it is not configured.
23-
if (! getenv('ROLLBAR_TOKEN') and ! $this->app['config']->get('services.rollbar')) {
23+
if ($this->stopRegistration() === true) {
2424
return;
2525
}
2626

@@ -51,35 +51,48 @@ public function boot()
5151
public function register()
5252
{
5353
// Don't register rollbar if it is not configured.
54-
if (! getenv('ROLLBAR_TOKEN') and ! $this->app['config']->get('services.rollbar')) {
54+
if ($this->stopRegistration() === true) {
5555
return;
5656
}
5757

5858
$app = $this->app;
5959

6060
$this->app->singleton('Rollbar\RollbarLogger', function ($app) {
61-
61+
6262
$defaults = [
6363
'environment' => $app->environment(),
6464
'root' => base_path(),
6565
];
6666
$config = array_merge($defaults, $app['config']->get('services.rollbar', []));
6767
$config['access_token'] = getenv('ROLLBAR_TOKEN') ?: $app['config']->get('services.rollbar.access_token');
68-
68+
6969
if (empty($config['access_token'])) {
7070
throw new InvalidArgumentException('Rollbar access token not configured');
7171
}
72-
72+
7373
\Rollbar\Rollbar::init($config);
74-
74+
7575
return Rollbar::logger();
7676
});
7777

7878
$this->app->singleton('Rollbar\Laravel\RollbarLogHandler', function ($app) {
79-
79+
8080
$level = getenv('ROLLBAR_LEVEL') ?: $app['config']->get('services.rollbar.level', 'debug');
8181

8282
return new RollbarLogHandler($app['Rollbar\RollbarLogger'], $app, $level);
8383
});
8484
}
85+
86+
/**
87+
* Check if we should prevent the service from registering
88+
*
89+
* @return boolean
90+
*/
91+
public function stopRegistration()
92+
{
93+
$hasToken = !empty(getenv('ROLLBAR_TOKEN'));
94+
$hasConfig = $this->app['config']->has('services.rollbar');
95+
96+
return $hasToken === false && $hasConfig === false;
97+
}
8598
}

0 commit comments

Comments
 (0)