1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Omatech\Mage\Core\Domains\Roles; |
4
|
|
|
|
5
|
|
|
use Omatech\Mage\Core\Domains\Permissions\Contracts\PermissionInterface; |
6
|
|
|
use Omatech\Mage\Core\Domains\Roles\Contracts\AllRoleInterface; |
7
|
|
|
use Omatech\Mage\Core\Domains\Roles\Contracts\FindRoleInterface; |
8
|
|
|
use Omatech\Mage\Core\Domains\Roles\Contracts\RoleInterface; |
9
|
|
|
use Omatech\Mage\Core\Domains\Roles\Features\ExistsAndDeleteRole; |
10
|
|
|
use Omatech\Mage\Core\Domains\Roles\Features\FindOrFailRole; |
11
|
|
|
use Omatech\Mage\Core\Domains\Roles\Features\UpdateOrCreateRole; |
12
|
|
|
use Omatech\Mage\Core\Domains\Shared\Traits\FromArray; |
13
|
|
|
use Omatech\Mage\Core\Domains\Shared\Traits\PermissionsManager; |
14
|
|
|
|
15
|
|
|
class Role implements RoleInterface |
16
|
|
|
{ |
17
|
|
|
use FromArray; |
18
|
|
|
use PermissionsManager; |
19
|
|
|
|
20
|
|
|
private $id; |
21
|
|
|
private $name; |
22
|
|
|
private $guardName; |
23
|
|
|
private $createdAt; |
24
|
|
|
private $updatedAt; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @return int|null |
28
|
|
|
*/ |
29
|
22 |
|
public function getId(): ?int |
30
|
|
|
{ |
31
|
22 |
|
return $this->id; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param int $id |
36
|
|
|
* @return $this |
37
|
|
|
*/ |
38
|
21 |
|
public function setId(int $id) |
39
|
|
|
{ |
40
|
21 |
|
$this->id = $id; |
41
|
|
|
|
42
|
21 |
|
return $this; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return string |
47
|
|
|
*/ |
48
|
21 |
|
public function getName(): string |
49
|
|
|
{ |
50
|
21 |
|
return $this->name; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param string $name |
55
|
|
|
* @return $this |
56
|
|
|
*/ |
57
|
23 |
|
public function setName(string $name) |
58
|
|
|
{ |
59
|
23 |
|
$this->name = $name; |
60
|
|
|
|
61
|
23 |
|
return $this; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return string |
66
|
|
|
*/ |
67
|
21 |
|
public function getGuardName(): string |
68
|
|
|
{ |
69
|
21 |
|
return $this->guardName; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param string $guardName |
74
|
|
|
* @return $this |
75
|
|
|
*/ |
76
|
23 |
|
public function setGuardName(string $guardName) |
77
|
|
|
{ |
78
|
23 |
|
$this->guardName = $guardName; |
79
|
|
|
|
80
|
23 |
|
return $this; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return string |
85
|
|
|
*/ |
86
|
5 |
|
public function getCreatedAt(): string |
87
|
|
|
{ |
88
|
5 |
|
return $this->createdAt; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param string $createdAt |
93
|
|
|
* @return $this |
94
|
|
|
*/ |
95
|
21 |
|
public function setCreatedAt(string $createdAt) |
96
|
|
|
{ |
97
|
21 |
|
$this->createdAt = $createdAt; |
98
|
|
|
|
99
|
21 |
|
return $this; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return string |
104
|
|
|
*/ |
105
|
5 |
|
public function getUpdatedAt(): string |
106
|
|
|
{ |
107
|
5 |
|
return $this->updatedAt; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param string $updatedAt |
112
|
|
|
* @return $this |
113
|
|
|
*/ |
114
|
21 |
|
public function setUpdatedAt(string $updatedAt) |
115
|
|
|
{ |
116
|
21 |
|
$this->updatedAt = $updatedAt; |
117
|
|
|
|
118
|
21 |
|
return $this; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return array |
123
|
|
|
*/ |
124
|
22 |
|
public function getPermissions(): array |
125
|
|
|
{ |
126
|
22 |
|
return $this->permissions; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @return array |
131
|
|
|
*/ |
132
|
21 |
|
public function getPermissionsIds(): array |
133
|
|
|
{ |
134
|
|
|
return array_map(static function (PermissionInterface $permission) { |
135
|
7 |
|
return $permission->getId(); |
136
|
21 |
|
}, $this->getPermissions()); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @param AllRoleInterface $all |
141
|
|
|
* @return mixed |
142
|
|
|
*/ |
143
|
1 |
|
public static function all(AllRoleInterface $all) |
144
|
|
|
{ |
145
|
1 |
|
return $all->get(); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @param FindRoleInterface $find |
150
|
|
|
* @param array $params |
151
|
|
|
* @return mixed |
152
|
|
|
* @throws Exceptions\RoleDoesNotExistsException |
153
|
|
|
*/ |
154
|
4 |
|
public static function find(FindRoleInterface $find, array $params) |
155
|
|
|
{ |
156
|
4 |
|
return (new FindOrFailRole())->make($find, $params); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @return bool |
161
|
|
|
* @throws Exceptions\RoleAlreadyExistsException |
162
|
|
|
* @throws Exceptions\RoleDoesNotExistsException |
163
|
|
|
* @throws Exceptions\RoleNameExistsMustBeUniqueException |
164
|
|
|
*/ |
165
|
21 |
|
public function save(): bool |
166
|
|
|
{ |
167
|
21 |
|
return (new UpdateOrCreateRole())->make($this); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @return bool |
172
|
|
|
* @throws Exceptions\RoleDoesNotExistsException |
173
|
|
|
* @throws Exceptions\RoleIsAttachedException |
174
|
|
|
*/ |
175
|
4 |
|
public function delete(): bool |
176
|
|
|
{ |
177
|
4 |
|
return (new ExistsAndDeleteRole())->make($this); |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|