@@ -28,7 +28,7 @@ |
||
28 | 28 | * PERMISSION |
29 | 29 | * A permission belongs to many users |
30 | 30 | * |
31 | - * @return mixed |
|
31 | + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
|
32 | 32 | */ |
33 | 33 | public function users() |
34 | 34 | { |
@@ -134,7 +134,7 @@ |
||
134 | 134 | { |
135 | 135 | parent::boot(); |
136 | 136 | |
137 | - static::deleting(function ($permission) { |
|
137 | + static::deleting(function($permission) { |
|
138 | 138 | $permission->users()->detach(); |
139 | 139 | $permission->level()->dissociate()->save(); |
140 | 140 | }); |
@@ -99,11 +99,13 @@ |
||
99 | 99 | */ |
100 | 100 | protected function getUser($user) |
101 | 101 | { |
102 | - if (is_int($user)) |
|
103 | - $user = config('laravel-acl.user')::find($user); |
|
102 | + if (is_int($user)) { |
|
103 | + $user = config('laravel-acl.user')::find($user); |
|
104 | + } |
|
104 | 105 | |
105 | - if (!$user) |
|
106 | - throw new UserNotFoundException; |
|
106 | + if (!$user) { |
|
107 | + throw new UserNotFoundException; |
|
108 | + } |
|
107 | 109 | |
108 | 110 | return $user; |
109 | 111 | } |
@@ -48,7 +48,7 @@ |
||
48 | 48 | { |
49 | 49 | parent::boot(); |
50 | 50 | |
51 | - static::deleting(function ($level) { |
|
51 | + static::deleting(function($level) { |
|
52 | 52 | $level->permissions()->where('level_id', $level->id)->update(['level_id' => null]); |
53 | 53 | foreach ($level->users as $user) { |
54 | 54 | $user->level()->dissociate()->save(); |
@@ -49,7 +49,7 @@ |
||
49 | 49 | return \Cache::remember( |
50 | 50 | 'laravel-acl.getNegatedPermissionsForUser_' . $this->id, |
51 | 51 | config('laravel-acl.cacheMinutes'), |
52 | - function () { |
|
52 | + function() { |
|
53 | 53 | return $this->cacheGetNegatedPermissions(); |
54 | 54 | } |
55 | 55 | ); |
@@ -2,8 +2,8 @@ |
||
2 | 2 | |
3 | 3 | namespace z1haze\Acl\Traits; |
4 | 4 | |
5 | -use z1haze\Acl\Exceptions\LevelNotFoundException; |
|
6 | 5 | use Illuminate\Support\Facades\Cache; |
6 | +use z1haze\Acl\Exceptions\LevelNotFoundException; |
|
7 | 7 | use z1haze\Acl\Models\Level; |
8 | 8 | |
9 | 9 | trait UserAndPermission |
@@ -60,7 +60,7 @@ |
||
60 | 60 | return Cache::remember( |
61 | 61 | 'laravel-acl.getLevelFor' . $model . '_' . $this->id, |
62 | 62 | config('laravel-acl.cacheMinutes'), |
63 | - function () { |
|
63 | + function() { |
|
64 | 64 | return $this->cacheGetLevel(); |
65 | 65 | } |
66 | 66 | ); |
@@ -94,14 +94,17 @@ |
||
94 | 94 | */ |
95 | 95 | protected function getALevel($level) |
96 | 96 | { |
97 | - if (is_string($level)) |
|
98 | - $level = config('laravel-acl.level', Level::class)::whereName($level)->first(); |
|
97 | + if (is_string($level)) { |
|
98 | + $level = config('laravel-acl.level', Level::class)::whereName($level)->first(); |
|
99 | + } |
|
99 | 100 | |
100 | - if (is_int($level)) |
|
101 | - $level = config('laravel-acl.level', Level::class)::find($level); |
|
101 | + if (is_int($level)) { |
|
102 | + $level = config('laravel-acl.level', Level::class)::find($level); |
|
103 | + } |
|
102 | 104 | |
103 | - if (!$level) |
|
104 | - throw new LevelNotFoundException(); |
|
105 | + if (!$level) { |
|
106 | + throw new LevelNotFoundException(); |
|
107 | + } |
|
105 | 108 | |
106 | 109 | return $level; |
107 | 110 | } |
@@ -354,7 +354,7 @@ |
||
354 | 354 | * Modify a given set of permissions, given the action to be taken |
355 | 355 | * |
356 | 356 | * @param $permissions |
357 | - * @param $action |
|
357 | + * @param string $action |
|
358 | 358 | */ |
359 | 359 | protected function modifyPermissions($permissions, $action) |
360 | 360 | { |
@@ -3,9 +3,9 @@ |
||
3 | 3 | namespace z1haze\Acl\Traits; |
4 | 4 | |
5 | 5 | use Illuminate\Support\Collection; |
6 | +use Illuminate\Support\Facades\Cache; |
|
6 | 7 | use ReflectionClass; |
7 | 8 | use z1haze\Acl\Exceptions\PermissionNotFoundException; |
8 | -use Illuminate\Support\Facades\Cache; |
|
9 | 9 | use z1haze\Acl\Models\Level; |
10 | 10 | use z1haze\Acl\Models\Permission; |
11 | 11 |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | return Cache::remember( |
123 | 123 | 'laravel-acl.getPermissionsFor' . (new ReflectionClass($this))->getShortName() . '_' . $this->id, |
124 | 124 | config('laravel-acl.cacheMinutes'), |
125 | - function () { |
|
125 | + function() { |
|
126 | 126 | return $this->cachegetPermissions(); |
127 | 127 | } |
128 | 128 | ); |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | return Cache::remember( |
143 | 143 | 'laravel-acl.getAllPermissionsFor' . (new ReflectionClass($this))->getShortName() . '_' . $this->id, |
144 | 144 | config('laravel-acl.cacheMinutes'), |
145 | - function () { |
|
145 | + function() { |
|
146 | 146 | return $this->cacheGetAllPermissions(); |
147 | 147 | } |
148 | 148 | ); |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | return Cache::remember( |
163 | 163 | 'laravel-acl.getInheritedPermissionsFor' . (new ReflectionClass($this))->getShortName() . '_' . $this->id, |
164 | 164 | config('laravel-acl.cacheMinutes'), |
165 | - function () { |
|
165 | + function() { |
|
166 | 166 | return $this->cacheGetInheritedPermissions(); |
167 | 167 | } |
168 | 168 | ); |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | return Cache::remember( |
183 | 183 | 'laravel-acl.getAvailablePermissionsFor' . (new ReflectionClass($this))->getShortName() . '_' . $this->id, |
184 | 184 | config('laravel-acl.cacheMinutes'), |
185 | - function () { |
|
185 | + function() { |
|
186 | 186 | return $this->cacheGetAvailablePermissions(); |
187 | 187 | } |
188 | 188 | ); |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | return Cache::remember( |
204 | 204 | 'laravel-acl.hasPermissionTo_' . (new ReflectionClass($this))->getShortName() . '_' . $this->id . '_Permission_' . $permission, |
205 | 205 | config('laravel-acl.cacheMinutes'), |
206 | - function () use ($permission) { |
|
206 | + function() use ($permission) { |
|
207 | 207 | return $this->cacheHasPermissionTo($permission); |
208 | 208 | } |
209 | 209 | ); |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | |
282 | 282 | $allPerms = new Collection(); |
283 | 283 | |
284 | - $levels->each(function ($level, $key) use (&$allPerms) { |
|
284 | + $levels->each(function($level, $key) use (&$allPerms) { |
|
285 | 285 | $allPerms = $allPerms->merge($level->permissions); |
286 | 286 | }); |
287 | 287 | |
@@ -300,12 +300,11 @@ discard block |
||
300 | 300 | $rank = is_a($this, config('laravel-acl.level'), true) ? $this->rank : $this->level->rank; |
301 | 301 | |
302 | 302 | $levels = is_a($this, config('laravel-acl.user'), true) ? |
303 | - config('laravel-acl.level', Level::class)::where('rank', '>=', $rank)->with('permissions')->get() : |
|
304 | - config('laravel-acl.level', Level::class)::where('rank', '>', $rank)->with('permissions')->get(); |
|
303 | + config('laravel-acl.level', Level::class)::where('rank', '>=', $rank)->with('permissions')->get() : config('laravel-acl.level', Level::class)::where('rank', '>', $rank)->with('permissions')->get(); |
|
305 | 304 | |
306 | 305 | $inheritedPerms = new Collection(); |
307 | 306 | |
308 | - $levels->each(function ($level, $key) use (&$inheritedPerms) { |
|
307 | + $levels->each(function($level, $key) use (&$inheritedPerms) { |
|
309 | 308 | $inheritedPerms = $inheritedPerms->merge($level->permissions->load('level')); |
310 | 309 | }); |
311 | 310 | |
@@ -399,8 +398,7 @@ discard block |
||
399 | 398 | $permissionsObjects[$permission->id] = ['negated' => true]; |
400 | 399 | } else { |
401 | 400 | is_a($this, config('laravel-acl.user')) ? |
402 | - array_push($permissionsObjects, $permission->id) : |
|
403 | - array_push($permissionsObjects, $permission); |
|
401 | + array_push($permissionsObjects, $permission->id) : array_push($permissionsObjects, $permission); |
|
404 | 402 | } |
405 | 403 | } |
406 | 404 | |
@@ -434,7 +432,7 @@ discard block |
||
434 | 432 | $this->permissions()->detach($permissionObjects); |
435 | 433 | |
436 | 434 | if (is_a($this, config('laravel-acl.level'))) { |
437 | - config('laravel-acl.permission', Permission::class)::whereIn('id', array_map(function ($permission) { |
|
435 | + config('laravel-acl.permission', Permission::class)::whereIn('id', array_map(function($permission) { |
|
438 | 436 | return $permission->id; |
439 | 437 | }, $permissionObjects))->update(['level_id' => null]); |
440 | 438 | } |
@@ -454,7 +452,7 @@ discard block |
||
454 | 452 | if (is_a($this, config('laravel-acl.level'))) { |
455 | 453 | $this->clearPermissions(); |
456 | 454 | |
457 | - config('laravel-acl.permission', Permission::class)::whereIn('id', array_map(function ($permission) { |
|
455 | + config('laravel-acl.permission', Permission::class)::whereIn('id', array_map(function($permission) { |
|
458 | 456 | return $permission->id; |
459 | 457 | }, $permissionObjects)) |
460 | 458 | ->update(['level_id' => $this->id]); |
@@ -101,11 +101,13 @@ discard block |
||
101 | 101 | */ |
102 | 102 | public function clearPermissions() |
103 | 103 | { |
104 | - if (is_a($this, config('laravel-acl.user'), true)) |
|
105 | - $this->permissions()->detach(); |
|
104 | + if (is_a($this, config('laravel-acl.user'), true)) { |
|
105 | + $this->permissions()->detach(); |
|
106 | + } |
|
106 | 107 | |
107 | - if (is_a($this, config('laravel-acl.level'), true)) |
|
108 | - config('laravel-acl.permission', Permission::class)::whereLevelId($this->id)->update(['level_id' => null]); |
|
108 | + if (is_a($this, config('laravel-acl.level'), true)) { |
|
109 | + config('laravel-acl.permission', Permission::class)::whereLevelId($this->id)->update(['level_id' => null]); |
|
110 | + } |
|
109 | 111 | } |
110 | 112 | |
111 | 113 | /** |
@@ -415,11 +417,13 @@ discard block |
||
415 | 417 | */ |
416 | 418 | protected function addOrNegate($permissionObjects) |
417 | 419 | { |
418 | - if (is_a($this, config('laravel-acl.user'))) |
|
419 | - $this->permissions()->attach($permissionObjects); |
|
420 | + if (is_a($this, config('laravel-acl.user'))) { |
|
421 | + $this->permissions()->attach($permissionObjects); |
|
422 | + } |
|
420 | 423 | |
421 | - if (is_a($this, config('laravel-acl.level'))) |
|
422 | - $this->permissions()->saveMany($permissionObjects); |
|
424 | + if (is_a($this, config('laravel-acl.level'))) { |
|
425 | + $this->permissions()->saveMany($permissionObjects); |
|
426 | + } |
|
423 | 427 | } |
424 | 428 | |
425 | 429 | /** |
@@ -430,8 +434,9 @@ discard block |
||
430 | 434 | */ |
431 | 435 | protected function remove($permissionObjects) |
432 | 436 | { |
433 | - if (is_a($this, config('laravel-acl.user'))) |
|
434 | - $this->permissions()->detach($permissionObjects); |
|
437 | + if (is_a($this, config('laravel-acl.user'))) { |
|
438 | + $this->permissions()->detach($permissionObjects); |
|
439 | + } |
|
435 | 440 | |
436 | 441 | if (is_a($this, config('laravel-acl.level'))) { |
437 | 442 | config('laravel-acl.permission', Permission::class)::whereIn('id', array_map(function ($permission) { |
@@ -448,8 +453,9 @@ discard block |
||
448 | 453 | */ |
449 | 454 | protected function sync($permissionObjects) |
450 | 455 | { |
451 | - if (is_a($this, config('laravel-acl.user'))) |
|
452 | - $this->permissions()->sync($permissionObjects); |
|
456 | + if (is_a($this, config('laravel-acl.user'))) { |
|
457 | + $this->permissions()->sync($permissionObjects); |
|
458 | + } |
|
453 | 459 | |
454 | 460 | if (is_a($this, config('laravel-acl.level'))) { |
455 | 461 | $this->clearPermissions(); |
@@ -472,14 +478,17 @@ discard block |
||
472 | 478 | */ |
473 | 479 | protected function getPermission($permission) |
474 | 480 | { |
475 | - if (is_string($permission)) |
|
476 | - $permission = config('laravel-acl.permission', Permission::class)::whereName($permission)->first(); |
|
481 | + if (is_string($permission)) { |
|
482 | + $permission = config('laravel-acl.permission', Permission::class)::whereName($permission)->first(); |
|
483 | + } |
|
477 | 484 | |
478 | - if (is_int($permission)) |
|
479 | - $permission = config('laravel-acl.permission', Permission::class)::find($permission); |
|
485 | + if (is_int($permission)) { |
|
486 | + $permission = config('laravel-acl.permission', Permission::class)::find($permission); |
|
487 | + } |
|
480 | 488 | |
481 | - if (!$permission) |
|
482 | - throw new PermissionNotFoundException; |
|
489 | + if (!$permission) { |
|
490 | + throw new PermissionNotFoundException; |
|
491 | + } |
|
483 | 492 | |
484 | 493 | return $permission; |
485 | 494 | } |