1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Ecodev\Felix\Acl\Assertion; |
||
6 | |||
7 | use Laminas\Permissions\Acl\Acl; |
||
8 | use Laminas\Permissions\Acl\Resource\ResourceInterface; |
||
9 | use Laminas\Permissions\Acl\Role\RoleInterface; |
||
10 | |||
11 | final class One implements NamedAssertion |
||
12 | { |
||
13 | /** |
||
14 | * @var NamedAssertion[] |
||
15 | */ |
||
16 | private readonly array $asserts; |
||
17 | |||
18 | /** |
||
19 | * Check if at least one assert is true. |
||
20 | */ |
||
21 | 8 | public function __construct(NamedAssertion ...$asserts) |
|
22 | { |
||
23 | 8 | $this->asserts = $asserts; |
|
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
24 | } |
||
25 | |||
26 | /** |
||
27 | * Assert that at least one of the given assert is correct (OR logic). |
||
28 | * |
||
29 | * @param \Ecodev\Felix\Acl\Acl $acl |
||
30 | * @param ?string $privilege |
||
31 | */ |
||
32 | 7 | public function assert(Acl $acl, ?RoleInterface $role = null, ?ResourceInterface $resource = null, $privilege = null): bool |
|
33 | { |
||
34 | 7 | foreach ($this->asserts as $assert) { |
|
35 | 6 | if ($assert->assert($acl, $role, $resource, $privilege)) { |
|
36 | 4 | return true; |
|
37 | } |
||
38 | } |
||
39 | |||
40 | 3 | return false; |
|
41 | } |
||
42 | |||
43 | 1 | public function getName(): string |
|
44 | { |
||
45 | 1 | return implode(_tr(', ou '), array_map(fn ($a) => $a->getName(), $this->asserts)); |
|
46 | } |
||
47 | } |
||
48 |