|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AuthService; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\ServiceProvider; |
|
6
|
|
|
|
|
7
|
|
|
class AuthServiceProvider extends ServiceProvider |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* Indicates if loading of the provider is deferred. |
|
11
|
|
|
* |
|
12
|
|
|
* @var bool |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $defer = true; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Perform post-registration booting of services. |
|
18
|
|
|
* |
|
19
|
|
|
* @return void |
|
20
|
|
|
*/ |
|
21
|
1 |
|
public function boot() |
|
22
|
|
|
{ |
|
23
|
1 |
|
$this->publishes([ |
|
24
|
1 |
|
__DIR__.'/../config/authservice.php' => config_path('authservice.php'), |
|
25
|
1 |
|
], 'config'); |
|
26
|
1 |
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Register the service provider. |
|
30
|
|
|
* |
|
31
|
|
|
* @return void |
|
32
|
|
|
*/ |
|
33
|
1 |
|
public function register() |
|
34
|
|
|
{ |
|
35
|
1 |
|
$this->registerAuthServiceConfig(); |
|
36
|
1 |
|
$this->registerAuthEventListener(); |
|
37
|
1 |
|
$this->registerAuthService(); |
|
38
|
1 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Register auth service configuration. |
|
42
|
|
|
* |
|
43
|
|
|
* @return void |
|
44
|
|
|
*/ |
|
45
|
1 |
|
protected function registerAuthServiceConfig() |
|
46
|
|
|
{ |
|
47
|
|
|
$this->app->singleton('AuthService\Contracts\AuthServiceConfigInterface', function ($app) { |
|
48
|
|
|
return \AuthService\AuthServiceConfig::fromArray($app['config']->get('authservice')); |
|
49
|
1 |
|
}); |
|
50
|
1 |
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Register auth event listener. |
|
54
|
|
|
* |
|
55
|
|
|
* @return void |
|
56
|
|
|
*/ |
|
57
|
1 |
|
protected function registerAuthEventListener() |
|
58
|
|
|
{ |
|
59
|
|
|
$this->app->singleton('AuthService\Contracts\AuthEventListenerInterface', function ($app) { |
|
60
|
|
|
$redirector = $app['redirect']; |
|
61
|
|
|
$config = $app->make('AuthService\Contracts\AuthServiceConfigInterface'); |
|
62
|
|
|
$eventListenerClass = $config->authEventListenerClass(); |
|
63
|
|
|
|
|
64
|
|
|
return new $eventListenerClass($redirector, $config); |
|
65
|
1 |
|
}); |
|
66
|
1 |
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Register auth service. |
|
70
|
|
|
* |
|
71
|
|
|
* @return void |
|
72
|
|
|
*/ |
|
73
|
|
|
protected function registerAuthService() |
|
74
|
|
|
{ |
|
75
|
1 |
|
$this->app->singleton('AuthService\Contracts\AuthServiceInterface', function ($app) { |
|
76
|
|
|
$statefulGuard = $app['auth']->guard(); |
|
77
|
|
|
$eventListener = $app->make('AuthService\Contracts\AuthEventListenerInterface'); |
|
78
|
|
|
|
|
79
|
|
|
return new \AuthService\AuthService($statefulGuard, $eventListener); |
|
80
|
1 |
|
}); |
|
81
|
1 |
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Get the services provided by the provider. |
|
85
|
|
|
* |
|
86
|
|
|
* @return array |
|
87
|
|
|
*/ |
|
88
|
1 |
|
public function provides() |
|
89
|
|
|
{ |
|
90
|
|
|
return [ |
|
91
|
1 |
|
'AuthService\Contracts\AuthServiceConfigInterface', |
|
92
|
1 |
|
'AuthService\Contracts\AuthEventListenerInterface', |
|
93
|
1 |
|
'AuthService\Contracts\AuthServiceInterface', |
|
94
|
1 |
|
]; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|