Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
95.00% |
19 / 20 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
RestApiRouteDefinitionProvider | |
95.00% |
19 / 20 |
|
50.00% |
1 / 2 |
6 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getActionsForBoundedContext | |
94.74% |
18 / 19 |
|
0.00% |
0 / 1 |
5.00 |
1 | <?php |
2 | namespace Apie\RestApi\RouteDefinitions; |
3 | |
4 | use Apie\Common\ActionDefinitionProvider; |
5 | use Apie\Common\Interfaces\RouteDefinitionProviderInterface; |
6 | use Apie\Common\RouteDefinitions\ActionHashmap; |
7 | use Apie\Core\BoundedContext\BoundedContext; |
8 | use Apie\Core\Context\ApieContext; |
9 | use Psr\Log\LoggerInterface; |
10 | |
11 | final class RestApiRouteDefinitionProvider implements RouteDefinitionProviderInterface |
12 | { |
13 | private const CLASSES = [ |
14 | CreateResourceRouteDefinition::class, |
15 | RemoveSingleResourceRouteDefinition::class, |
16 | GetResourceListRouteDefinition::class, |
17 | GetSingleResourceRouteDefinition::class, |
18 | PatchSingleResourceRouteDefinition::class, |
19 | RunGlobalMethodRouteDefinition::class, |
20 | RunMethodCallOnSingleResourceRouteDefinition::class, |
21 | StreamMethodCallOnSingleResourceRouteDefinition::class, |
22 | ]; |
23 | |
24 | public function __construct( |
25 | private ActionDefinitionProvider $actionDefinitionProvider, |
26 | private LoggerInterface $logger, |
27 | ) { |
28 | } |
29 | |
30 | public function getActionsForBoundedContext(BoundedContext $boundedContext, ApieContext $apieContext): ActionHashmap |
31 | { |
32 | $routes = []; |
33 | $definition = new OpenApiDocumentationRouteDefinition(true, $boundedContext->getId()); |
34 | $routes[$definition->getOperationId()] = $definition; |
35 | $definition = new OpenApiDocumentationRouteDefinition(false, $boundedContext->getId()); |
36 | $routes[$definition->getOperationId()] = $definition; |
37 | $definition = new SwaggerUIRouteDefinition($boundedContext->getId()); |
38 | $routes[$definition->getOperationId()] = $definition; |
39 | $definition = new SwaggerUIRedirectRouteDefinition($boundedContext->getId()); |
40 | $routes[$definition->getOperationId()] = $definition; |
41 | |
42 | foreach ($this->actionDefinitionProvider->provideActionDefinitions($boundedContext, $apieContext) as $actionDefinition) { |
43 | $found = false; |
44 | foreach (self::CLASSES as $routeDefinitionClass) { |
45 | $routeDefinition = $routeDefinitionClass::createFrom($actionDefinition); |
46 | if ($routeDefinition) { |
47 | $routes[$routeDefinition->getOperationId()] = $routeDefinition; |
48 | $found = true; |
49 | } |
50 | } |
51 | if (!$found) { |
52 | $this->logger->debug('No route definition created for ' . get_debug_type($actionDefinition)); |
53 | } |
54 | } |
55 | return new ActionHashmap($routes); |
56 | } |
57 | } |