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