Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| BoundedContextProviderContextBuilder | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| process | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | namespace Apie\Common\ContextBuilders; |
| 3 | |
| 4 | use Apie\Core\BoundedContext\BoundedContext; |
| 5 | use Apie\Core\BoundedContext\BoundedContextHashmap; |
| 6 | use Apie\Core\Context\ApieContext; |
| 7 | use Apie\Core\ContextBuilders\ContextBuilderInterface; |
| 8 | use Apie\Core\ContextConstants; |
| 9 | |
| 10 | class BoundedContextProviderContextBuilder implements ContextBuilderInterface |
| 11 | { |
| 12 | public function __construct(private readonly BoundedContextHashmap $boundedContextHashmap) |
| 13 | { |
| 14 | } |
| 15 | |
| 16 | public function process(ApieContext $context): ApieContext |
| 17 | { |
| 18 | $context = $context->registerInstance($this->boundedContextHashmap); |
| 19 | if ($context->hasContext(ContextConstants::BOUNDED_CONTEXT_ID) && !$context->hasContext(BoundedContext::class)) { |
| 20 | $id = $context->getContext(ContextConstants::BOUNDED_CONTEXT_ID); |
| 21 | if (isset($this->boundedContextHashmap[$id])) { |
| 22 | return $context->withContext(BoundedContext::class, $this->boundedContextHashmap[$id]); |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | return $context; |
| 27 | } |
| 28 | } |