Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
12 / 12 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| ApieCallTypeResolver | |
100.00% |
12 / 12 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __invoke | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | namespace Apie\Graphql\TypeResolvers; |
| 3 | |
| 4 | use Apie\Core\Actions\ActionInterface; |
| 5 | use Apie\Core\Actions\ApieFacadeInterface; |
| 6 | use Apie\Core\BoundedContext\BoundedContextId; |
| 7 | use Apie\Core\Context\ApieContext; |
| 8 | use Apie\Core\ContextConstants; |
| 9 | use ReflectionClass; |
| 10 | |
| 11 | class ApieCallTypeResolver |
| 12 | { |
| 13 | /** |
| 14 | * @param class-string<ActionInterface> $actionClass |
| 15 | */ |
| 16 | public function __construct( |
| 17 | private readonly string $actionClass, |
| 18 | private readonly ?BoundedContextId $boundedContextId = null, |
| 19 | private readonly ?ReflectionClass $resourceClass = null, |
| 20 | ) { |
| 21 | } |
| 22 | public function __invoke(ApieContext $context, array $args): array |
| 23 | { |
| 24 | $contextVariables = $this->actionClass::getRouteAttributes($this->resourceClass); |
| 25 | $contextVariables[ContextConstants::APIE_ACTION] = $this->actionClass; |
| 26 | $contextVariables[ContextConstants::RAW_CONTENTS] = $args['input'] ?? []; |
| 27 | if ($this->boundedContextId) { |
| 28 | $contextVariables[ContextConstants::BOUNDED_CONTEXT_ID] = $this->boundedContextId->toNative(); |
| 29 | $contextVariables[BoundedContextId::class] = $this->boundedContextId; |
| 30 | } |
| 31 | $context = $context->withMultipleContext($contextVariables); |
| 32 | $facade = $context->getContext(ApieFacadeInterface::class); |
| 33 | $action = new $this->actionClass($facade); |
| 34 | $response = $action->__invoke($context, $args['input'] ?? []); |
| 35 | |
| 36 | return json_decode(json_encode($response->getResultAsNativeData()), true); |
| 37 | } |
| 38 | } |