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 (false === class_exists('CreateLoginsTable') && false === class_exists('CreateDevicesTable')) { |
24
|
|
|
$this->publishes([ |
25
|
|
|
__DIR__.'/../migrations/create_devices_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_devices_table.php'), |
26
|
|
|
__DIR__.'/../migrations/create_logins_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_logins_table.php') |
27
|
|
|
], 'auth-checker'); |
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function register(): void |
32
|
|
|
{ |
33
|
|
|
$this->mergeConfigFrom(__DIR__.'/../config/auth-checker.php', 'auth-checker'); |
34
|
|
|
|
35
|
|
|
$this->loadTranslationsFrom(__DIR__.'/../lang/', 'auth-checker'); |
36
|
|
|
|
37
|
|
|
$this->app->singleton(AuthChecker::class, function ($app) { |
38
|
|
|
return new AuthChecker($app, $app['request']); |
39
|
|
|
}); |
40
|
|
|
|
41
|
|
|
$this->app->alias(AuthChecker::class, 'authchecker'); |
42
|
|
|
|
43
|
|
|
$this->app->register(AgentServiceProvider::class); |
44
|
|
|
|
45
|
|
|
/** @var Dispatcher $dispatcher */ |
46
|
|
|
$dispatcher = $this->app['events']; |
47
|
|
|
$dispatcher->subscribe(AuthCheckerSubscriber::class); |
48
|
|
|
} |
49
|
|
|
} |