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