|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Omatech\Mage\Core\Domains\Shared\Traits; |
|
4
|
|
|
|
|
5
|
|
|
use Omatech\Mage\Core\Domains\Permissions\Contracts\PermissionInterface; |
|
6
|
|
|
use Omatech\Mage\Core\Domains\Permissions\Exceptions\PermissionIsNotSavedException; |
|
7
|
|
|
use Omatech\Mage\Core\Domains\Permissions\PermissionModel; |
|
8
|
|
|
|
|
9
|
|
|
trait PermissionsManager |
|
10
|
|
|
{ |
|
11
|
|
|
private $permissions = []; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @return mixed |
|
15
|
|
|
*/ |
|
16
|
|
|
abstract public function getPermissions(); |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @param PermissionInterface $permission |
|
20
|
|
|
* @return self |
|
21
|
|
|
* @throws PermissionIsNotSavedException |
|
22
|
|
|
*/ |
|
23
|
3 |
|
public function assignPermission(PermissionInterface $permission) |
|
24
|
|
|
{ |
|
25
|
3 |
|
$this->permissions = (new PermissionModel()) |
|
26
|
3 |
|
->assignPermission($this->getPermissions(), $permission); |
|
27
|
|
|
|
|
28
|
3 |
|
return $this; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param array $permissions |
|
33
|
|
|
* @return self |
|
34
|
|
|
* @throws PermissionIsNotSavedException |
|
35
|
|
|
*/ |
|
36
|
14 |
|
public function assignPermissions(array $permissions) |
|
37
|
|
|
{ |
|
38
|
14 |
|
$this->permissions = (new PermissionModel()) |
|
39
|
14 |
|
->assignPermissions($this->getPermissions(), $permissions); |
|
40
|
|
|
|
|
41
|
12 |
|
return $this; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param PermissionInterface $permission |
|
46
|
|
|
* @return self |
|
47
|
|
|
* @throws PermissionIsNotSavedException |
|
48
|
|
|
*/ |
|
49
|
2 |
|
public function removePermission(PermissionInterface $permission) |
|
50
|
|
|
{ |
|
51
|
2 |
|
$this->permissions = (new PermissionModel()) |
|
52
|
2 |
|
->removePermission($this->getPermissions(), $permission); |
|
53
|
|
|
|
|
54
|
2 |
|
return $this; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param array $permissions |
|
59
|
|
|
* @return self |
|
60
|
|
|
* @throws PermissionIsNotSavedException |
|
61
|
|
|
*/ |
|
62
|
4 |
|
public function removePermissions(array $permissions) |
|
63
|
|
|
{ |
|
64
|
4 |
|
$this->permissions = (new PermissionModel()) |
|
65
|
4 |
|
->removePermissions($this->getPermissions(), $permissions); |
|
66
|
|
|
|
|
67
|
2 |
|
return $this; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|