|
24 | 24 |
|
25 | 25 | namespace Bottledcode\DurablePhp; |
26 | 26 |
|
| 27 | +use Bottledcode\DurablePhp\Events\GiveOwnership; |
27 | 28 | use Bottledcode\DurablePhp\Events\RaiseEvent; |
| 29 | +use Bottledcode\DurablePhp\Events\RevokeRole; |
| 30 | +use Bottledcode\DurablePhp\Events\RevokeUser; |
| 31 | +use Bottledcode\DurablePhp\Events\ShareOwnership; |
| 32 | +use Bottledcode\DurablePhp\Events\Shares\Operation; |
| 33 | +use Bottledcode\DurablePhp\Events\ShareWithRole; |
| 34 | +use Bottledcode\DurablePhp\Events\ShareWithUser; |
28 | 35 | use Bottledcode\DurablePhp\Events\StartExecution; |
29 | 36 | use Bottledcode\DurablePhp\Events\TaskCompleted; |
30 | 37 | use Bottledcode\DurablePhp\Events\WithDelay; |
@@ -188,4 +195,64 @@ public function currentUserId(): string |
188 | 195 | { |
189 | 196 | return $this->user->userId; |
190 | 197 | } |
| 198 | + |
| 199 | + public function shareOwnership(string $withUser): void |
| 200 | + { |
| 201 | + $this->eventDispatcher->fire( |
| 202 | + WithEntity::forInstance( |
| 203 | + StateId::fromEntityId($this->id), |
| 204 | + ShareOwnership::withUser($withUser), |
| 205 | + ), |
| 206 | + ); |
| 207 | + } |
| 208 | + |
| 209 | + public function giveOwnership(string $withUser): void |
| 210 | + { |
| 211 | + $this->eventDispatcher->fire( |
| 212 | + WithEntity::forInstance( |
| 213 | + StateId::fromEntityId($this->id), |
| 214 | + GiveOwnership::withUser($withUser), |
| 215 | + ), |
| 216 | + ); |
| 217 | + } |
| 218 | + |
| 219 | + public function grantUser(string $withUser, Operation ...$operation): void |
| 220 | + { |
| 221 | + $this->eventDispatcher->fire( |
| 222 | + WithEntity::forInstance( |
| 223 | + StateId::fromEntityId($this->id), |
| 224 | + ShareWithUser::For($withUser, ...$operation), |
| 225 | + ), |
| 226 | + ); |
| 227 | + } |
| 228 | + |
| 229 | + public function grantRole(string $withRole, Operation ...$operation): void |
| 230 | + { |
| 231 | + $this->eventDispatcher->fire( |
| 232 | + WithEntity::forInstance( |
| 233 | + StateId::fromEntityId($this->id), |
| 234 | + ShareWithRole::For($withRole, ...$operation), |
| 235 | + ), |
| 236 | + ); |
| 237 | + } |
| 238 | + |
| 239 | + public function revokeUser(string $user): void |
| 240 | + { |
| 241 | + $this->eventDispatcher->fire( |
| 242 | + WithEntity::forInstance( |
| 243 | + StateId::fromEntityId($this->id), |
| 244 | + RevokeUser::completely($user), |
| 245 | + ), |
| 246 | + ); |
| 247 | + } |
| 248 | + |
| 249 | + public function revokeRole(string $role): void |
| 250 | + { |
| 251 | + $this->eventDispatcher->fire( |
| 252 | + WithEntity::forInstance( |
| 253 | + StateId::fromEntityId($this->id), |
| 254 | + RevokeRole::completely($role), |
| 255 | + ), |
| 256 | + ); |
| 257 | + } |
191 | 258 | } |
0 commit comments