Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
95.65% |
22 / 23 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| CreateEntityListContextBuilder | |
95.65% |
22 / 23 |
|
0.00% |
0 / 1 |
9 | |
0.00% |
0 / 1 |
| process | |
95.65% |
22 / 23 |
|
0.00% |
0 / 1 |
9 | |||
| 1 | <?php |
| 2 | namespace Apie\Core\ContextBuilders; |
| 3 | |
| 4 | use Apie\Core\BoundedContext\BoundedContextHashmap; |
| 5 | use Apie\Core\BoundedContext\BoundedContextId; |
| 6 | use Apie\Core\Context\ApieContext; |
| 7 | use Apie\Core\ContextConstants; |
| 8 | use Apie\Core\Datalayers\ApieDatalayer; |
| 9 | use Apie\Core\Datalayers\Lists\EntityListInterface; |
| 10 | |
| 11 | class CreateEntityListContextBuilder implements ContextBuilderInterface |
| 12 | { |
| 13 | public function process(ApieContext $context): ApieContext |
| 14 | { |
| 15 | $apieDatalayer = $context->getContext(ApieDatalayer::class, false); |
| 16 | $hashmap = $context->getContext(BoundedContextHashmap::class, false); |
| 17 | if (!$context->hasContext(ContextConstants::BOUNDED_CONTEXT_ID) |
| 18 | || !$context->hasContext(ContextConstants::RESOURCE_NAME) |
| 19 | || $context->hasContext(ContextConstants::RESOURCE_ID) |
| 20 | || $apieDatalayer === null |
| 21 | || $hashmap === null |
| 22 | ) { |
| 23 | return $context; |
| 24 | } |
| 25 | |
| 26 | $boundedContextId = new BoundedContextId($context->getContext(ContextConstants::BOUNDED_CONTEXT_ID)); |
| 27 | $resourceName = $context->getContext(ContextConstants::RESOURCE_NAME); |
| 28 | $boundedContext = $hashmap[$boundedContextId->toNative()] ?? null; |
| 29 | foreach ($boundedContext->resources ?? [] as $resource) { |
| 30 | if ($resource->getShortName() === $resourceName || $resource->name === $resourceName) { |
| 31 | return $context |
| 32 | ->withContext( |
| 33 | EntityListInterface::class, |
| 34 | $apieDatalayer->all($resource, $boundedContextId) |
| 35 | ) |
| 36 | ->withContext( |
| 37 | ContextConstants::RESOURCE_NAME, |
| 38 | $resource->name |
| 39 | ); |
| 40 | } |
| 41 | } |
| 42 | return $context; |
| 43 | } |
| 44 | } |