ServiceProvider::loadRoutes()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace AtlassianConnectCore;
4
5
use Illuminate\Foundation\Application;
6
use Illuminate\Support\Facades\Auth;
7
use Illuminate\Support\Facades\Route;
8
9
/**
10
 * Class ServiceProvider
11
 *
12
 * @package AtlassianConnectCore
13
 */
14
class ServiceProvider extends \Illuminate\Support\ServiceProvider
15
{
16
    /**
17
     * Indicates if loading of the provider is deferred.
18
     *
19
     * @var bool
20
     */
21
    protected $defer = false;
22
23
    /**
24
     * Perform post-registration booting of services.
25
     *
26
     * @return void
27
     */
28
    public function boot()
29
    {
30
        $this->loadPublishes();
31
        $this->loadRoutes();
32
        $this->loadMigrations();
33
        $this->loadConsoleCommands();
34
        $this->loadViews();
35
    }
36
37
    /**
38
     * Register any package services.
39
     *
40
     * @return void
41
     */
42
    public function register()
43
    {
44
        $this->mergeConfigFrom(
45
            __DIR__ . '/../config/plugin.php', 'plugin'
46
        );
47
48
        $this->registerFacades();
49
        $this->registerJWTGuard();
50
    }
51
52
    /**
53
     * Load publishes
54
     */
55
    protected function loadPublishes()
56
    {
57
        $this->publishes([__DIR__ . '/../config/plugin.php' => config_path('plugin.php')], 'config');
58
        $this->publishes([__DIR__ . '/../resources/views' => resource_path('views/vendor/plugin')], 'views');
59
        $this->publishes([__DIR__ . '/../resources/assets' => public_path('vendor/plugin')], 'public');
60
    }
61
62
    /**
63
     * Load routes
64
     */
65
    protected function loadRoutes()
66
    {
67
        if(config('plugin.loadRoutes')) {
68
            $this->loadRoutesFrom(__DIR__ . '/Http/routes.php');
69
        }
70
71
        Route::getRoutes()->refreshNameLookups();
72
    }
73
74
    /**
75
     * Load migrations
76
     */
77
    protected function loadMigrations()
78
    {
79
        $this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
80
    }
81
82
    /**
83
     * Load console commands
84
     */
85
    protected function loadConsoleCommands()
86
    {
87
        if(!$this->app->runningInConsole()) {
88
            return;
89
        }
90
91
        $this->commands([
92
            \AtlassianConnectCore\Console\InstallCommand::class,
93
            \AtlassianConnectCore\Console\DummyCommand::class
94
        ]);
95
    }
96
97
    /**
98
     * Load views
99
     */
100
    protected function loadViews()
101
    {
102
        $this->loadViewsFrom(__DIR__ . '/../resources/views', 'plugin');
103
    }
104
105
    /**
106
     * Register package facades
107
     */
108
    protected function registerFacades()
109
    {
110
        $this->app->bind('descriptor', Descriptor::class);
111
    }
112
113
    /**
114
     * Register JWT guard
115
     */
116
    protected function registerJWTGuard()
117
    {
118
        Auth::extend('jwt', function (Application $app, $name, array $config)
119
        {
120
            return $app->makeWith(JWTGuard::class, [
121
                'provider' => Auth::createUserProvider($config['provider']),
122
                'session' => $app['session.store'],
123
                'cookie' => $app['cookie']
124
            ]);
125
        });
126
    }
127
}