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
|
|
|
/** @var bool */ |
18
|
|
|
protected $defer = false; |
19
|
|
|
|
20
|
|
|
/** @var string */ |
21
|
|
|
protected $name = 'auth-checker'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Register the service provider. |
25
|
|
|
* |
26
|
|
|
* @return void |
27
|
|
|
*/ |
28
|
|
|
public function register() |
29
|
|
|
{ |
30
|
|
|
$this->app->bind(AuthChecker::class, AuthChecker::class); |
31
|
|
|
|
32
|
|
|
$this->app->singleton(AuthChecker::class, function ($app) { |
33
|
|
|
return new AuthChecker($app, $app['request']); |
34
|
|
|
}); |
35
|
|
|
|
36
|
|
|
$this->app->alias(AuthChecker::class, 'authchecker'); |
37
|
|
|
|
38
|
|
|
$this->registerDependencies(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Bootstrap the application events. |
43
|
|
|
* |
44
|
|
|
* @return void |
45
|
|
|
*/ |
46
|
|
|
public function boot() |
47
|
|
|
{ |
48
|
|
|
$this->mergeConfig() |
49
|
|
|
->mergeLang() |
50
|
|
|
->mergeMigrations() |
51
|
|
|
->registerEvents(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param void |
56
|
|
|
* @return self |
57
|
|
|
*/ |
58
|
|
|
protected function registerDependencies() |
59
|
|
|
{ |
60
|
|
|
$this->app->register(AgentServiceProvider::class); |
61
|
|
|
|
62
|
|
|
return $this; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Merge migration files. |
67
|
|
|
* |
68
|
|
|
* @param void |
69
|
|
|
* @return self |
70
|
|
|
*/ |
71
|
|
|
protected function mergeMigrations() |
72
|
|
|
{ |
73
|
|
|
$this->loadMigrationsFrom(__DIR__ . '/../migrations'); |
74
|
|
|
|
75
|
|
|
return $this; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Merge config file. |
80
|
|
|
* |
81
|
|
|
* @param void |
82
|
|
|
* @return self |
83
|
|
|
*/ |
84
|
|
|
protected function mergeConfig() |
85
|
|
|
{ |
86
|
|
|
$configPath = __DIR__ . '/../config/' . $this->name . '.php'; |
87
|
|
|
|
88
|
|
|
$this->mergeConfigFrom($configPath, $this->name); |
89
|
|
|
|
90
|
|
|
$this->publishes([$configPath => config_path($this->name . '.php')], 'auth-checker'); |
91
|
|
|
|
92
|
|
|
return $this; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Publish lang files. |
97
|
|
|
* |
98
|
|
|
* @param void |
99
|
|
|
* @return self |
100
|
|
|
*/ |
101
|
|
|
protected function mergeLang() |
102
|
|
|
{ |
103
|
|
|
$langPath = __DIR__ . '/../lang/'; |
104
|
|
|
|
105
|
|
|
$this->loadTranslationsFrom($langPath, $this->name); |
106
|
|
|
|
107
|
|
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Registers library events. |
112
|
|
|
* |
113
|
|
|
* @param void |
114
|
|
|
* @return self |
115
|
|
|
*/ |
116
|
|
|
protected function registerEvents() |
117
|
|
|
{ |
118
|
|
|
/** @var Dispatcher $dispatcher */ |
119
|
|
|
$dispatcher = $this->app['events']; |
120
|
|
|
$dispatcher->subscribe(AuthCheckerSubscriber::class); |
121
|
|
|
|
122
|
|
|
return $this; |
123
|
|
|
} |
124
|
|
|
} |