Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
3 / 3 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| Grant | |
100.00% |
3 / 3 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isActiveAt | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| allows | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace LambdaTwelve\OneRecord\Server\Spi; |
| 6 | |
| 7 | use DateTimeImmutable; |
| 8 | use LambdaTwelve\OneRecord\Api\Permission; |
| 9 | use LambdaTwelve\OneRecord\Rdf\Iri; |
| 10 | |
| 11 | /** |
| 12 | * Access an organisation holds on a logistics object: from the holder |
| 13 | * directly, or through an accepted access delegation. |
| 14 | */ |
| 15 | final readonly class Grant |
| 16 | { |
| 17 | /** |
| 18 | * @param non-empty-list<Permission> $permissions |
| 19 | * @param ?Iri $source the access delegation request that granted it, null for the holder's own grants |
| 20 | */ |
| 21 | public function __construct( |
| 22 | public Iri $agent, |
| 23 | public Iri $logisticsObject, |
| 24 | public array $permissions, |
| 25 | public ?DateTimeImmutable $expiresAt = null, |
| 26 | public ?Iri $source = null, |
| 27 | ) {} |
| 28 | |
| 29 | public function isActiveAt(DateTimeImmutable $now): bool |
| 30 | { |
| 31 | return $this->expiresAt === null || $this->expiresAt > $now; |
| 32 | } |
| 33 | |
| 34 | public function allows(Permission $permission): bool |
| 35 | { |
| 36 | return \in_array($permission, $this->permissions, true); |
| 37 | } |
| 38 | } |