AuthCheckerServiceProvider::boot()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 9.1448
c 0
b 0
f 0
cc 5
nc 5
nop 0
1
<?php
2
3
namespace Lab404\AuthChecker;
4
5
use Illuminate\Events\Dispatcher;
6
use Jenssegers\Agent\AgentServiceProvider;
7
use Lab404\AuthChecker\Services\AuthChecker;
8
use Lab404\AuthChecker\Subscribers\AuthCheckerSubscriber;
9
10
/**
11
 * Class AuthCheckerServiceProvider
12
 *
13
 * @package Lab404\AuthChecker
14
 */
15
class AuthCheckerServiceProvider extends \Illuminate\Support\ServiceProvider
16
{
17
    public function boot(): void
18
    {
19
        $this->publishes([
20
            __DIR__.'/../config/auth-checker.php' => config_path('auth-checker.php')
21
        ], 'auth-checker');
22
23
        if ($this->app->runningInConsole()) {
24
            if (false === class_exists('CreateLoginsTable') && false === class_exists('CreateDevicesTable')) {
25
                $this->publishes([
26
                    __DIR__.'/../migrations/create_devices_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_devices_table.php'),
27
                    __DIR__.'/../migrations/create_logins_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_logins_table.php')
28
                ], 'auth-checker');
29
            }
30
31
            if (false === class_exists('UpdateLoginsAndDevicesTableUserRelation')) {
32
                $this->publishes([
33
                    __DIR__.'/../migrations/update_logins_and_devices_table_user_relation.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_update_logins_and_devices_table_user_relation.php'),
34
                ], 'auth-checker');
35
            }
36
        }
37
38
        $this->mergeConfigFrom(__DIR__.'/../config/auth-checker.php', 'auth-checker');
39
40
        $this->loadTranslationsFrom(__DIR__.'/../lang/', 'auth-checker');
41
42
        /** @var Dispatcher $dispatcher */
43
        $dispatcher = $this->app['events'];
44
        $dispatcher->subscribe(AuthCheckerSubscriber::class);
45
    }
46
47
    public function register(): void
48
    {
49
        $this->app->singleton(AuthChecker::class, function ($app) {
50
            return new AuthChecker($app, $app['request']);
51
        });
52
53
        $this->app->alias(AuthChecker::class, 'authchecker');
54
55
        $this->app->register(AgentServiceProvider::class);
56
    }
57
}