|
1
|
|
|
<?php namespace Arcanesoft\Auth\Providers; |
|
2
|
|
|
|
|
3
|
|
|
use Arcanesoft\Contracts\Auth\Models\User; |
|
4
|
|
|
use Illuminate\Contracts\Auth\Access\Gate as GateContract; |
|
5
|
|
|
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class AuthorizationServiceProvider |
|
9
|
|
|
* |
|
10
|
|
|
* @package Arcanesoft\Auth\Providers |
|
11
|
|
|
* @author ARCANEDEV <[email protected]> |
|
12
|
|
|
*/ |
|
13
|
|
|
class AuthorizationServiceProvider extends ServiceProvider |
|
14
|
|
|
{ |
|
15
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
16
|
|
|
| Properties |
|
17
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
18
|
|
|
*/ |
|
19
|
|
|
/** |
|
20
|
|
|
* The policy mappings for the application. |
|
21
|
|
|
* |
|
22
|
|
|
* @var array |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $policies = [ |
|
25
|
|
|
// |
|
26
|
|
|
]; |
|
27
|
|
|
|
|
28
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
29
|
|
|
| Main Functions |
|
30
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
31
|
|
|
*/ |
|
32
|
|
|
/** |
|
33
|
|
|
* Register any application authentication / authorization services. |
|
34
|
|
|
* |
|
35
|
|
|
* @param \Illuminate\Contracts\Auth\Access\Gate $gate |
|
36
|
|
|
*/ |
|
37
|
24 |
|
public function boot(GateContract $gate) |
|
38
|
|
|
{ |
|
39
|
24 |
|
parent::registerPolicies($gate); |
|
|
|
|
|
|
40
|
|
|
|
|
41
|
24 |
|
$this->registerUsersPolicies($gate); |
|
42
|
24 |
|
$this->registerRolesPolicies($gate); |
|
43
|
24 |
|
$this->registerPermissionsPolicies($gate); |
|
44
|
24 |
|
$this->registerOtherPolicies($gate); |
|
45
|
24 |
|
} |
|
46
|
|
|
|
|
47
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
48
|
|
|
| Policies |
|
49
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
50
|
|
|
*/ |
|
51
|
|
|
/** |
|
52
|
|
|
* Register users authorizations. |
|
53
|
|
|
* |
|
54
|
|
|
* @param \Illuminate\Contracts\Auth\Access\Gate $gate |
|
55
|
|
|
*/ |
|
56
|
24 |
|
private function registerUsersPolicies(GateContract $gate) |
|
57
|
|
|
{ |
|
58
|
|
|
$gate->define('auth.users.list', function (User $user) { |
|
59
|
|
|
return $user->may('auth.users.list'); |
|
60
|
24 |
|
}); |
|
61
|
|
|
|
|
62
|
|
|
$gate->define('auth.users.show', function (User $user) { |
|
63
|
|
|
return $user->may('auth.users.show'); |
|
64
|
24 |
|
}); |
|
65
|
|
|
|
|
66
|
|
|
$gate->define('auth.users.create', function (User $user) { |
|
67
|
|
|
return $user->may('auth.users.create'); |
|
68
|
24 |
|
}); |
|
69
|
|
|
|
|
70
|
|
|
$gate->define('auth.users.update', function (User $user) { |
|
71
|
|
|
return $user->may('auth.users.update'); |
|
72
|
24 |
|
}); |
|
73
|
|
|
|
|
74
|
|
|
$gate->define('auth.users.delete', function (User $user) { |
|
75
|
|
|
return $user->may('auth.users.delete'); |
|
76
|
24 |
|
}); |
|
77
|
24 |
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Register roles authorizations. |
|
81
|
|
|
* |
|
82
|
|
|
* @param \Illuminate\Contracts\Auth\Access\Gate $gate |
|
83
|
|
|
*/ |
|
84
|
24 |
|
private function registerRolesPolicies(GateContract $gate) |
|
85
|
|
|
{ |
|
86
|
|
|
$gate->define('auth.roles.list', function (User $user) { |
|
87
|
|
|
return $user->may('auth.roles.list'); |
|
88
|
24 |
|
}); |
|
89
|
|
|
|
|
90
|
|
|
$gate->define('auth.roles.show', function (User $user) { |
|
91
|
|
|
return $user->may('auth.roles.show'); |
|
92
|
24 |
|
}); |
|
93
|
|
|
|
|
94
|
|
|
$gate->define('auth.roles.create', function (User $user) { |
|
95
|
|
|
return $user->may('auth.roles.create'); |
|
96
|
24 |
|
}); |
|
97
|
|
|
|
|
98
|
|
|
$gate->define('auth.roles.update', function (User $user) { |
|
99
|
|
|
return $user->may('auth.roles.update'); |
|
100
|
24 |
|
}); |
|
101
|
|
|
|
|
102
|
|
|
$gate->define('auth.roles.delete', function (User $user) { |
|
103
|
|
|
return $user->may('auth.roles.delete'); |
|
104
|
24 |
|
}); |
|
105
|
24 |
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Register permissions authorizations. |
|
109
|
|
|
* |
|
110
|
|
|
* @param \Illuminate\Contracts\Auth\Access\Gate $gate |
|
111
|
|
|
*/ |
|
112
|
24 |
|
private function registerPermissionsPolicies(GateContract $gate) |
|
113
|
|
|
{ |
|
114
|
|
|
$gate->define('auth.permissions.list', function (User $user) { |
|
115
|
|
|
return $user->may('auth.permissions.list'); |
|
116
|
24 |
|
}); |
|
117
|
|
|
|
|
118
|
|
|
$gate->define('auth.permissions.show', function (User $user) { |
|
119
|
|
|
return $user->may('auth.permissions.show'); |
|
120
|
24 |
|
}); |
|
121
|
|
|
|
|
122
|
|
|
$gate->define('auth.permissions.update', function (User $user) { |
|
123
|
|
|
return $user->may('auth.permissions.update'); |
|
124
|
24 |
|
}); |
|
125
|
24 |
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Register other authorizations for auth module. |
|
129
|
|
|
* |
|
130
|
|
|
* @param \Illuminate\Contracts\Auth\Access\Gate $gate |
|
131
|
|
|
*/ |
|
132
|
|
|
private function registerOtherPolicies(GateContract $gate) |
|
133
|
|
|
{ |
|
134
|
24 |
|
$gate->define('auth.dashboard.stats', function (User $user) { |
|
135
|
|
|
return $user->may('auth.dashboard.stats'); |
|
136
|
24 |
|
}); |
|
137
|
24 |
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.