1
|
|
|
<?php namespace Arcanedev\LaravelAuth\Providers; |
2
|
|
|
|
3
|
|
|
use Arcanedev\Support\Providers\EventServiceProvider as ServiceProvider; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class EventServiceProvider |
7
|
|
|
* |
8
|
|
|
* @package Arcanedev\LaravelAuth\Providers |
9
|
|
|
* @author ARCANEDEV <[email protected]> |
10
|
|
|
*/ |
11
|
|
|
class EventServiceProvider extends ServiceProvider |
12
|
|
|
{ |
13
|
|
|
/* ------------------------------------------------------------------------------------------------ |
14
|
|
|
| Main Functions |
15
|
|
|
| ------------------------------------------------------------------------------------------------ |
16
|
|
|
*/ |
17
|
|
|
/** |
18
|
|
|
* {@inheritdoc} |
19
|
|
|
*/ |
20
|
612 |
|
public function register() |
21
|
|
|
{ |
22
|
612 |
|
parent::register(); |
23
|
|
|
|
24
|
612 |
|
$this->app->booted(function () { |
25
|
612 |
|
$this->registerObservers(); |
26
|
612 |
|
}); |
27
|
612 |
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Register the application's event listeners. |
31
|
|
|
*/ |
32
|
612 |
|
protected function registerObservers() |
33
|
|
|
{ |
34
|
|
|
$observers = [ |
35
|
612 |
|
'users' => \Arcanesoft\Contracts\Auth\Models\User::class, |
36
|
204 |
|
'roles' => \Arcanesoft\Contracts\Auth\Models\Role::class, |
37
|
204 |
|
'permissions-groups' => \Arcanesoft\Contracts\Auth\Models\PermissionsGroup::class, |
38
|
204 |
|
'permissions' => \Arcanesoft\Contracts\Auth\Models\Permission::class, |
39
|
204 |
|
]; |
40
|
|
|
|
41
|
612 |
|
foreach ($observers as $name => $abstract) { |
42
|
612 |
|
$this->observe($name, $abstract); |
43
|
204 |
|
} |
44
|
612 |
|
} |
45
|
|
|
|
46
|
|
|
/* ------------------------------------------------------------------------------------------------ |
47
|
|
|
| Other Functions |
48
|
|
|
| ------------------------------------------------------------------------------------------------ |
49
|
|
|
*/ |
50
|
|
|
/** |
51
|
|
|
* Observe the model. |
52
|
|
|
* |
53
|
|
|
* @param string $name |
54
|
|
|
* @param string $abstract |
55
|
|
|
*/ |
56
|
612 |
|
private function observe($name, $abstract) |
57
|
|
|
{ |
58
|
612 |
|
$this->getModel($abstract)->observe( |
59
|
612 |
|
$this->getObserver($name) |
60
|
204 |
|
); |
61
|
612 |
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Get the concrete model. |
65
|
|
|
* |
66
|
|
|
* @param string $abstract |
67
|
|
|
* |
68
|
|
|
* @return \Illuminate\Database\Eloquent\Model |
69
|
|
|
*/ |
70
|
612 |
|
private function getModel($abstract) |
71
|
|
|
{ |
72
|
612 |
|
return $this->app->make($abstract); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Get the observer class. |
77
|
|
|
* |
78
|
|
|
* @param string $key |
79
|
|
|
* |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
612 |
|
private function getObserver($key) |
83
|
|
|
{ |
84
|
|
|
/** @var \Illuminate\Contracts\Config\Repository $config */ |
85
|
612 |
|
$config = $this->app['config']; |
86
|
|
|
|
87
|
612 |
|
return $config->get("laravel-auth.{$key}.observer"); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|