Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
97.22% |
35 / 36 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
CmsRouteDefinitionProvider | |
97.22% |
35 / 36 |
|
50.00% |
1 / 2 |
13 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getActionsForBoundedContext | |
97.14% |
34 / 35 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | namespace Apie\Cms\RouteDefinitions; |
3 | |
4 | use Apie\CmsApiDropdownOption\RouteDefinitions\DropdownOptionsForExistingObjectRouteDefinition; |
5 | use Apie\CmsApiDropdownOption\RouteDefinitions\DropdownOptionsForGlobalMethodRouteDefinition; |
6 | use Apie\CmsApiDropdownOption\RouteDefinitions\DropdownOptionsForNewObjectRouteDefinition; |
7 | use Apie\Common\ActionDefinitionProvider; |
8 | use Apie\Common\ActionDefinitions\CreateResourceActionDefinition; |
9 | use Apie\Common\ActionDefinitions\ModifyResourceActionDefinition; |
10 | use Apie\Common\ActionDefinitions\ReplaceResourceActionDefinition; |
11 | use Apie\Common\ActionDefinitions\RunGlobalMethodDefinition; |
12 | use Apie\Common\Interfaces\RouteDefinitionProviderInterface; |
13 | use Apie\Common\RouteDefinitions\ActionHashmap; |
14 | use Apie\Core\BoundedContext\BoundedContext; |
15 | use Apie\Core\Context\ApieContext; |
16 | use Psr\Log\LoggerInterface; |
17 | |
18 | class CmsRouteDefinitionProvider implements RouteDefinitionProviderInterface |
19 | { |
20 | private const CLASSES = [ |
21 | CreateResourceFormRouteDefinition::class, |
22 | CreateResourceCommitRouteDefinition::class, |
23 | DisplayResourceRouteDefinition::class, |
24 | DisplayResourceOverviewRouteDefinition::class, |
25 | ModifyResourceFormRouteDefinition::class, |
26 | ModifyResourceCommitRouteDefinition::class, |
27 | RemoveResourceFormRouteDefinition::class, |
28 | RemoveResourceFormCommitRouteDefinition::class, |
29 | RunGlobalMethodCommitRouteDefinition::class, |
30 | RunGlobalMethodFormRouteDefinition::class, |
31 | RunMethodCallOnSingleResourceCommitRouteDefinition::class, |
32 | RunMethodCallOnSingleResourceFormRouteDefinition::class, |
33 | StreamMethodCallOnSingleResourceRouteDefinition::class, |
34 | ]; |
35 | |
36 | public function __construct( |
37 | private ActionDefinitionProvider $actionDefinitionProvider, |
38 | private LoggerInterface $logger, |
39 | ) { |
40 | } |
41 | |
42 | public function getActionsForBoundedContext(BoundedContext $boundedContext, ApieContext $apieContext): ActionHashmap |
43 | { |
44 | $routes = []; |
45 | $definition = new DashboardRouteDefinition($boundedContext->getId()); |
46 | $routes[$definition->getOperationId()] = $definition; |
47 | $definition = new LastActionResultRouteDefinition($boundedContext->getId()); |
48 | $routes[$definition->getOperationId()] = $definition; |
49 | foreach ($this->actionDefinitionProvider->provideActionDefinitions($boundedContext, $apieContext) as $actionDefinition) { |
50 | $found = false; |
51 | foreach (self::CLASSES as $routeDefinitionClass) { |
52 | $routeDefinition = $routeDefinitionClass::createFrom($actionDefinition); |
53 | if ($routeDefinition) { |
54 | $routes[$routeDefinition->getOperationId()] = $routeDefinition; |
55 | $found = true; |
56 | } |
57 | } |
58 | if (class_exists(DropdownOptionsForNewObjectRouteDefinition::class) && |
59 | ($actionDefinition instanceof CreateResourceActionDefinition || $actionDefinition instanceof ReplaceResourceActionDefinition)) { |
60 | $routeDefinition = new DropdownOptionsForNewObjectRouteDefinition( |
61 | $actionDefinition->getResourceName(), |
62 | $actionDefinition->getBoundedContextId(), |
63 | ); |
64 | $routes[$routeDefinition->getOperationId()] = $routeDefinition; |
65 | } |
66 | if (class_exists(DropdownOptionsForExistingObjectRouteDefinition::class) && $actionDefinition instanceof ModifyResourceActionDefinition) { |
67 | $routeDefinition = new DropdownOptionsForExistingObjectRouteDefinition( |
68 | $actionDefinition->getResourceName(), |
69 | $actionDefinition->getBoundedContextId(), |
70 | ); |
71 | $routes[$routeDefinition->getOperationId()] = $routeDefinition; |
72 | } |
73 | if (class_exists(DropdownOptionsForGlobalMethodRouteDefinition::class) && $actionDefinition instanceof RunGlobalMethodDefinition) { |
74 | $routeDefinition = new DropdownOptionsForGlobalMethodRouteDefinition( |
75 | $actionDefinition->getMethod()->getDeclaringClass(), |
76 | $actionDefinition->getBoundedContextId(), |
77 | $actionDefinition->getMethod(), |
78 | ); |
79 | $routes[$routeDefinition->getOperationId()] = $routeDefinition; |
80 | } |
81 | if (!$found) { |
82 | $this->logger->debug('No route definition created for ' . get_debug_type($actionDefinition)); |
83 | } |
84 | } |
85 | |
86 | return new ActionHashmap($routes); |
87 | } |
88 | } |