Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
9 / 9 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| GetResourceActionDefinition | |
100.00% |
9 / 9 |
|
100.00% |
4 / 4 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getResourceName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getBoundedContextId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| provideActionDefinitions | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | namespace Apie\Common\ActionDefinitions; |
| 3 | |
| 4 | use Apie\Core\BoundedContext\BoundedContext; |
| 5 | use Apie\Core\BoundedContext\BoundedContextId; |
| 6 | use Apie\Core\Context\ApieContext; |
| 7 | use Apie\Core\ContextConstants; |
| 8 | use Apie\Core\Entities\EntityInterface; |
| 9 | use ReflectionClass; |
| 10 | |
| 11 | /** |
| 12 | * Action definition for getting a single resource by id in a specific bounded context. |
| 13 | */ |
| 14 | final class GetResourceActionDefinition implements ActionDefinitionInterface |
| 15 | { |
| 16 | /** |
| 17 | * @param ReflectionClass<EntityInterface> $resourceName |
| 18 | */ |
| 19 | public function __construct( |
| 20 | private readonly ReflectionClass $resourceName, |
| 21 | private readonly BoundedContextId $boundedContextId |
| 22 | ) { |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * @return ReflectionClass<EntityInterface> |
| 27 | */ |
| 28 | public function getResourceName(): ReflectionClass |
| 29 | { |
| 30 | return $this->resourceName; |
| 31 | } |
| 32 | |
| 33 | public function getBoundedContextId(): BoundedContextId |
| 34 | { |
| 35 | return $this->boundedContextId; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Business logic for getting single resources: |
| 40 | * - ContextConstants::GET_OBJECT restrictions can be added if it is not wanted |
| 41 | */ |
| 42 | public static function provideActionDefinitions(BoundedContext $boundedContext, ApieContext $apieContext, bool $runtimeChecks = false): array |
| 43 | { |
| 44 | $actionDefinitions = []; |
| 45 | $getSingleContext = $apieContext->withContext(ContextConstants::GET_OBJECT, true) |
| 46 | ->registerInstance($boundedContext); |
| 47 | foreach ($boundedContext->resources->filterOnApieContext($getSingleContext, $runtimeChecks) as $resource) { |
| 48 | $actionDefinitions[] = new GetResourceActionDefinition($resource, $boundedContext->getId()); |
| 49 | } |
| 50 | return $actionDefinitions; |
| 51 | } |
| 52 | } |