Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
GetResourceListController
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __invoke
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2namespace Apie\Cms\Controllers;
3
4use Apie\Cms\Services\ResponseFactory;
5use Apie\Common\ApieFacade;
6use Apie\Core\BoundedContext\BoundedContextId;
7use Apie\Core\ContextBuilders\ContextBuilderFactory;
8use Apie\Core\ContextConstants;
9use Apie\HtmlBuilders\Factories\ComponentFactory;
10use Psr\Http\Message\ResponseInterface;
11use Psr\Http\Message\ServerRequestInterface;
12use ReflectionClass;
13
14class 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    }
38}