Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
69.23% |
9 / 13 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| BoundedContextSelected | |
69.23% |
9 / 13 |
|
66.67% |
2 / 3 |
8.43 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getBoundedContextFromRequest | |
63.64% |
7 / 11 |
|
0.00% |
0 / 1 |
6.20 | |||
| getBoundedContextFromClassName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Apie\LaravelApie\Wrappers\Core; |
| 3 | |
| 4 | use Apie\Common\Interfaces\BoundedContextSelection; |
| 5 | use Apie\Core\BoundedContext\BoundedContext; |
| 6 | use Apie\Core\BoundedContext\BoundedContextHashmap; |
| 7 | use Apie\Core\ContextConstants; |
| 8 | |
| 9 | final class BoundedContextSelected implements BoundedContextSelection |
| 10 | { |
| 11 | public function __construct(private readonly BoundedContextHashmap $boundedContextHashmap) |
| 12 | { |
| 13 | } |
| 14 | |
| 15 | public function getBoundedContextFromRequest(): ?BoundedContext |
| 16 | { |
| 17 | $request = app('request'); |
| 18 | if (!$request) { |
| 19 | return null; |
| 20 | } |
| 21 | $route = $request->route(); |
| 22 | if ($route) { |
| 23 | $parameters = $route->parameters(); |
| 24 | if (isset($parameters[ContextConstants::BOUNDED_CONTEXT_ID])) { |
| 25 | return $this->boundedContextHashmap[$parameters[ContextConstants::BOUNDED_CONTEXT_ID]]; |
| 26 | } |
| 27 | if (isset($parameters[ContextConstants::RESOURCE_NAME])) { |
| 28 | return $this->getBoundedContextFromClassName($parameters[ContextConstants::RESOURCE_NAME]); |
| 29 | } |
| 30 | } |
| 31 | return null; |
| 32 | } |
| 33 | |
| 34 | public function getBoundedContextFromClassName(string $className): ?BoundedContext |
| 35 | { |
| 36 | return null; |
| 37 | } |
| 38 | } |