@@ -13,13 +13,13 @@ |
||
13 | 13 | |
14 | 14 | interface VoterProvider |
15 | 15 | { |
16 | - /** |
|
17 | - * Returns a voter for a permission. |
|
18 | - * |
|
19 | - * The dispatcher should fail if the function returns `null`, but a chain of voter providers |
|
20 | - * could invoke the next voter provider. |
|
21 | - * |
|
22 | - * @throws VoterNotFound |
|
23 | - */ |
|
24 | - public function getVoterForPermission(string $permission): ?Voter; |
|
16 | + /** |
|
17 | + * Returns a voter for a permission. |
|
18 | + * |
|
19 | + * The dispatcher should fail if the function returns `null`, but a chain of voter providers |
|
20 | + * could invoke the next voter provider. |
|
21 | + * |
|
22 | + * @throws VoterNotFound |
|
23 | + */ |
|
24 | + public function getVoterForPermission(string $permission): ?Voter; |
|
25 | 25 | } |
@@ -19,10 +19,10 @@ |
||
19 | 19 | */ |
20 | 20 | class VoterNotFound extends LogicException implements Exception |
21 | 21 | { |
22 | - public function __construct( |
|
23 | - public string $permission, |
|
24 | - ?Throwable $previous = null |
|
25 | - ) { |
|
26 | - parent::__construct("Voter not found for permission: $permission", 0, $previous); |
|
27 | - } |
|
22 | + public function __construct( |
|
23 | + public string $permission, |
|
24 | + ?Throwable $previous = null |
|
25 | + ) { |
|
26 | + parent::__construct("Voter not found for permission: $permission", 0, $previous); |
|
27 | + } |
|
28 | 28 | } |
@@ -16,8 +16,8 @@ |
||
16 | 16 | */ |
17 | 17 | interface Voter |
18 | 18 | { |
19 | - /** |
|
20 | - * Returns `true` when permission is granted, ending the voting process positively. |
|
21 | - */ |
|
22 | - public function isGranted(object $message, Context $context): bool; |
|
19 | + /** |
|
20 | + * Returns `true` when permission is granted, ending the voting process positively. |
|
21 | + */ |
|
22 | + public function isGranted(object $message, Context $context): bool; |
|
23 | 23 | } |
@@ -16,30 +16,30 @@ |
||
16 | 16 | */ |
17 | 17 | final class VoterWithPermissions implements Voter |
18 | 18 | { |
19 | - /** |
|
20 | - * @param array<class-string, string[]> $permissionsByMessage |
|
21 | - * Where _key_ is a command class and _value_ the permissions for that message. |
|
22 | - */ |
|
23 | - public function __construct( |
|
24 | - private VoterProvider $voters, |
|
25 | - private array $permissionsByMessage, |
|
26 | - ) { |
|
27 | - } |
|
19 | + /** |
|
20 | + * @param array<class-string, string[]> $permissionsByMessage |
|
21 | + * Where _key_ is a command class and _value_ the permissions for that message. |
|
22 | + */ |
|
23 | + public function __construct( |
|
24 | + private VoterProvider $voters, |
|
25 | + private array $permissionsByMessage, |
|
26 | + ) { |
|
27 | + } |
|
28 | 28 | |
29 | - public function isGranted(object $message, Context $context): bool |
|
30 | - { |
|
31 | - $permissions = $this->permissionsByMessage[$message::class] ?? null; |
|
29 | + public function isGranted(object $message, Context $context): bool |
|
30 | + { |
|
31 | + $permissions = $this->permissionsByMessage[$message::class] ?? null; |
|
32 | 32 | |
33 | - if (!$permissions) { |
|
34 | - return true; |
|
35 | - } |
|
33 | + if (!$permissions) { |
|
34 | + return true; |
|
35 | + } |
|
36 | 36 | |
37 | - foreach ($permissions as $permission) { |
|
38 | - if ($this->voters->getVoterForPermission($permission)?->isGranted($message, $context)) { |
|
39 | - return true; |
|
40 | - } |
|
41 | - } |
|
37 | + foreach ($permissions as $permission) { |
|
38 | + if ($this->voters->getVoterForPermission($permission)?->isGranted($message, $context)) { |
|
39 | + return true; |
|
40 | + } |
|
41 | + } |
|
42 | 42 | |
43 | - return false; |
|
44 | - } |
|
43 | + return false; |
|
44 | + } |
|
45 | 45 | } |