Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
12 / 12 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| GetResourceListController | |
100.00% |
12 / 12 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __invoke | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Apie\Cms\Controllers; |
| 3 | |
| 4 | use Apie\Cms\Services\ResponseFactory; |
| 5 | use Apie\Common\ApieFacade; |
| 6 | use Apie\Core\BoundedContext\BoundedContextId; |
| 7 | use Apie\Core\ContextBuilders\ContextBuilderFactory; |
| 8 | use Apie\Core\ContextConstants; |
| 9 | use Apie\HtmlBuilders\Factories\ComponentFactory; |
| 10 | use Psr\Http\Message\ResponseInterface; |
| 11 | use Psr\Http\Message\ServerRequestInterface; |
| 12 | use ReflectionClass; |
| 13 | |
| 14 | class GetResourceListController |
| 15 | { |
| 16 | public function __construct( |
| 17 | private readonly ApieFacade $apieFacade, |
| 18 | private readonly ComponentFactory $componentFactory, |
| 19 | private readonly ContextBuilderFactory $contextBuilderFactory, |
| 20 | private readonly ResponseFactory $responseFactory |
| 21 | ) { |
| 22 | } |
| 23 | |
| 24 | public function __invoke(ServerRequestInterface $request): ResponseInterface |
| 25 | { |
| 26 | $context = $this->contextBuilderFactory->createFromRequest($request, [ContextConstants::CMS => true]); |
| 27 | |
| 28 | $action = $this->apieFacade->createAction($context); |
| 29 | $data = ($action)($context, $context->getContext(ContextConstants::RAW_CONTENTS)); |
| 30 | $component = $this->componentFactory->createResourceOverview( |
| 31 | $data, |
| 32 | new ReflectionClass($request->getAttribute(ContextConstants::RESOURCE_NAME)), |
| 33 | new BoundedContextId($context->getContext(ContextConstants::BOUNDED_CONTEXT_ID)) |
| 34 | ); |
| 35 | |
| 36 | return $this->responseFactory->createComponentPageRender($component, $data->apieContext) |
| 37 | ->withHeader('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0') |
| 38 | ->withHeader('Pragma', 'no-cache'); |
| 39 | ; |
| 40 | } |
| 41 | } |