Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
10 / 10 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| ActionDefinitionProvider | |
100.00% |
10 / 10 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| provideActionDefinitions | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | namespace Apie\Common; |
| 3 | |
| 4 | use Apie\Common\ActionDefinitions\ActionDefinitionInterface; |
| 5 | use Apie\Common\ActionDefinitions\CreateResourceActionDefinition; |
| 6 | use Apie\Common\ActionDefinitions\DownloadFilesActionDefinition; |
| 7 | use Apie\Common\ActionDefinitions\GetResourceActionDefinition; |
| 8 | use Apie\Common\ActionDefinitions\GetResourceListActionDefinition; |
| 9 | use Apie\Common\ActionDefinitions\ModifyResourceActionDefinition; |
| 10 | use Apie\Common\ActionDefinitions\RemoveResourceActionDefinition; |
| 11 | use Apie\Common\ActionDefinitions\ReplaceResourceActionDefinition; |
| 12 | use Apie\Common\ActionDefinitions\RunGlobalMethodDefinition; |
| 13 | use Apie\Common\ActionDefinitions\RunResourceMethodDefinition; |
| 14 | use Apie\Common\ContextBuilders\ServiceContextBuilder; |
| 15 | use Apie\Common\Lists\ActionDefinitionList; |
| 16 | use Apie\Core\BoundedContext\BoundedContext; |
| 17 | use Apie\Core\BoundedContext\BoundedContextId; |
| 18 | use Apie\Core\Context\ApieContext; |
| 19 | use Apie\Core\ContextConstants; |
| 20 | use Symfony\Component\DependencyInjection\ServiceLocator; |
| 21 | |
| 22 | class ActionDefinitionProvider |
| 23 | { |
| 24 | /** |
| 25 | * @var array<int, class-string<ActionDefinitionInterface>> |
| 26 | */ |
| 27 | private const ACTION_DEFINITION_CLASSES = [ |
| 28 | CreateResourceActionDefinition::class, |
| 29 | ReplaceResourceActionDefinition::class, |
| 30 | GetResourceActionDefinition::class, |
| 31 | GetResourceListActionDefinition::class, |
| 32 | ModifyResourceActionDefinition::class, |
| 33 | RemoveResourceActionDefinition::class, |
| 34 | RunGlobalMethodDefinition::class, |
| 35 | RunResourceMethodDefinition::class, |
| 36 | DownloadFilesActionDefinition::class, |
| 37 | ]; |
| 38 | |
| 39 | private ServiceContextBuilder $serviceContextBuilder; |
| 40 | |
| 41 | /** |
| 42 | * @param ServiceLocator<object> $serviceLocator |
| 43 | */ |
| 44 | public function __construct(ServiceLocator $serviceLocator) |
| 45 | { |
| 46 | $this->serviceContextBuilder = new ServiceContextBuilder($serviceLocator); |
| 47 | } |
| 48 | |
| 49 | public function provideActionDefinitions(BoundedContext $boundedContext, ApieContext $apieContext, bool $runtimeChecks = false): ActionDefinitionList |
| 50 | { |
| 51 | $apieContext = $this->serviceContextBuilder->process($apieContext) |
| 52 | ->withContext(BoundedContext::class, $boundedContext) |
| 53 | ->withContext(BoundedContextId::class, $boundedContext->getId()) |
| 54 | ->withContext(ContextConstants::BOUNDED_CONTEXT_ID, $boundedContext->getId()->toNative()); |
| 55 | $actionDefinitions = []; |
| 56 | foreach (self::ACTION_DEFINITION_CLASSES as $actionDefinitionClass) { |
| 57 | foreach ($actionDefinitionClass::provideActionDefinitions($boundedContext, $apieContext, $runtimeChecks) as $actionDefinition) { |
| 58 | $actionDefinitions[] = $actionDefinition; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | return new ActionDefinitionList($actionDefinitions); |
| 63 | } |
| 64 | } |