Test Failed
Pull Request — master (#13)
by
unknown
18:55
created

LaravelAuthApiServiceProvider::boot()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 36

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 36
ccs 0
cts 9
cp 0
rs 9.344
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
namespace MedianetDev\LaravelAuthApi;
4
5
use Illuminate\Support\ServiceProvider;
6
7
class LaravelAuthApiServiceProvider extends ServiceProvider
8
{
9
    protected $commands = [
10
        \MedianetDev\LaravelAuthApi\Console\Commands\PublishApiUserModel::class,
11
    ];
12
13
    /**
14
     * Bootstrap the application services.
15
     */
16
    public function boot(\Illuminate\Routing\Router $router)
0 ignored issues
show
Unused Code introduced by
The parameter $router is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
17
    {
18
        /*
19
         * Optional methods to load your package assets
20
         */
21
        // $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'laravel-auth-api');
22
        // $this->loadViewsFrom(__DIR__.'/../resources/views', 'laravel-auth-api');
23
        $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
24
        $this->loadRoutesFrom(__DIR__.'/routes.php');
25
26
        $this->loadConfigs();
27
28
        if ($this->app->runningInConsole()) {
29
            $this->publishes([
30
                __DIR__.'/../config/config.php' => config_path('laravel-auth-api.php'),
31
            ], 'config');
32
33
            // Publishing the views.
34
            /*$this->publishes([
35
                __DIR__.'/../resources/views' => resource_path('views/vendor/laravel-auth-api'),
36
            ], 'views');*/
37
38
            // Publishing assets.
39
            /*$this->publishes([
40
                __DIR__.'/../resources/assets' => public_path('vendor/laravel-auth-api'),
41
            ], 'assets');*/
42
43
            // Publishing the translation files.
44
            /*$this->publishes([
45
                __DIR__.'/../resources/lang' => resource_path('lang/vendor/laravel-auth-api'),
46
            ], 'lang');*/
47
48
            // Registering package commands.
49
            // $this->commands([]);
50
        }
51
    }
52
53
    /**
54
     * Register the application services.
55
     */
56
    public function register()
57
    {
58
        // Automatically apply the package configuration
59
        $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'laravel-auth-api');
60
61
        // Register the main class to use with the facade
62
        $this->app->singleton('laravel-auth-api', function () {
63
            return new LaravelAuthApi;
64
        });
65
66
        // register the artisan commands
67
        $this->commands($this->commands);
68
    }
69
70
    public function loadConfigs()
71
    {
72
        // dd(config('laravel-auth-api.user_model_fqn'));
73
        // add the backpack_users authentication provider to the configuration
74
        app()->config['auth.providers'] = app()->config['auth.providers'] +
75
        [
76
            'apiauth' => [
77
                'driver'  => 'eloquent',
78
                'model'   => config('laravel-auth-api.user_model_fqn') ?: \MedianetDev\LaravelAuthApi\Models\ApiUser::class,
79
            ],
80
        ];
81
        // add the backpack_users password broker to the configuration
82
        app()->config['auth.passwords'] = app()->config['auth.passwords'] +
83
        [
84
            'apiauth' => [
85
                'provider'  => 'apiauth',
86
                'table'     => 'password_resets',
87
                'expire'    => 15,
88
            ],
89
        ];
90
        // add the backpack_users guard to the configuration
91
        app()->config['auth.guards'] = app()->config['auth.guards'] +
92
        [
93
            'apiauth' => [
94
                'driver'   => 'passport',
95
                'provider' => 'apiauth',
96
            ],
97
        ];
98
        // just to resolve the Auth::guard()->attempt() problem in the login controller
99
        app()->config['auth.guards'] = app()->config['auth.guards'] +
100
        [
101
            'apiauthweb' => [
102
                'driver'   => 'session',
103
                'provider' => 'apiauth',
104
            ],
105
        ];
106
    }
107
}
108