FlightDeckServiceProvider::boot()   A
last analyzed

Complexity

Conditions 5
Paths 16

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 9.1128
c 0
b 0
f 0
cc 5
nc 16
nop 0
1
<?php
2
3
namespace Yab\FlightDeck;
4
5
use Illuminate\Support\ServiceProvider;
6
use Yab\FlightDeck\Commands\ListTokens;
7
use Yab\FlightDeck\Http\Middleware\Cors;
8
use Yab\FlightDeck\Commands\GenerateToken;
9
use Yab\FlightDeck\Http\Middleware\Authorization;
10
11
class FlightDeckServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * Bootstrap the application services.
15
     */
16
    public function boot()
17
    {
18
        /*
19
         * Optional methods to load your package assets
20
         */
21
        $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'flightdeck');
22
        $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
23
        
24
        if (config('flightdeck.authentication.enabled')) {
25
            $this->loadRoutesFrom(__DIR__ . '/routes/auth.php');
26
        }
27
28
        if (config('flightdeck.authorization.enabled')) {
29
            $this->app['router']->aliasMiddleware('flightdeck', Authorization::class);
30
        }
31
        
32
        if (config('flightdeck.cors.enabled')) {
33
            $this->app['router']->aliasMiddleware('cors', Cors::class);
34
        }
35
36
        if ($this->app->runningInConsole()) {
37
            $this->publishes([
38
                __DIR__.'/../config/config.php' => config_path('flightdeck.php'),
39
            ], 'config');
40
41
            // Publishing the translation files.
42
            $this->publishes([
43
                __DIR__.'/../resources/lang' => resource_path('lang/vendor/flightdeck'),
44
            ], 'lang');
45
        }
46
    }
47
48
    /**
49
     * Register the application services.
50
     */
51
    public function register()
52
    {
53
        // Automatically apply the package configuration
54
        $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'flightdeck');
55
56
        $this->commands([
57
            GenerateToken::class,
58
            ListTokens::class,
59
        ]);
60
    }
61
}
62