Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| RuntimeCheck | |
100.00% |
5 / 5 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| applies | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | namespace Apie\Core\Attributes; |
| 3 | |
| 4 | use Apie\Core\Context\ApieContext; |
| 5 | use Attribute; |
| 6 | |
| 7 | /** |
| 8 | * Checks all attributes on runtime context checks. A runtime context check is for example |
| 9 | * if it requires permission to modify something. |
| 10 | * |
| 11 | * A static context check is always done and is for example used to generate the routing rules. |
| 12 | */ |
| 13 | #[Attribute(Attribute::IS_REPEATABLE|Attribute::TARGET_CLASS|Attribute::TARGET_METHOD|Attribute::TARGET_PROPERTY|Attribute::TARGET_PARAMETER|Attribute::TARGET_CLASS_CONSTANT)] |
| 14 | final class RuntimeCheck implements ApieContextAttribute |
| 15 | { |
| 16 | /** |
| 17 | * @var ApieContextAttribute[] |
| 18 | */ |
| 19 | private array $checks; |
| 20 | |
| 21 | public function __construct(ApieContextAttribute... $checks) |
| 22 | { |
| 23 | $this->checks = $checks; |
| 24 | } |
| 25 | |
| 26 | public function applies(ApieContext $context): bool |
| 27 | { |
| 28 | foreach ($this->checks as $check) { |
| 29 | if (!$check->applies($context)) { |
| 30 | return false; |
| 31 | } |
| 32 | } |
| 33 | return true; |
| 34 | } |
| 35 | } |