DemoModeServiceProvider::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Spatie\DemoMode;
4
5
use Illuminate\Support\ServiceProvider;
6
7
class DemoModeServiceProvider extends ServiceProvider
8
{
9
    /**
10
     * Bootstrap the application services.
11
     */
12
    public function boot()
13
    {
14
        $this->publishes([
15
            __DIR__.'/../config/demo-mode.php' => config_path('demo-mode.php'),
16
        ], 'config');
17
    }
18
19
    /**
20
     * Register the application services.
21
     */
22
    public function register()
23
    {
24
        $this->mergeConfigFrom(__DIR__.'/../config/demo-mode.php', 'demo-mode');
25
26
        $router = $this->app['router'];
27
28
        $router->macro('demoAccess', function ($url) use ($router) {
29
            if (!config('demo-mode.enabled') || config('demo-mode.strict_mode')) {
30
                return;
31
            }
32
33
            $router->get($url, '\Spatie\DemoMode\DemoModeController@grantAccess');
34
        });
35
36
        $router->fallback('\Spatie\DemoMode\DemoModeController@catchFallback');
37
38
        $this->app->singleton(DemoGuard::class, config('demo-mode.guard'));
39
    }
40
}
41