Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
CreateResourceFormController
100.00% covered (success)
100.00%
15 / 15
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%
14 / 14
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2namespace Apie\Cms\Controllers;
3
4use Apie\Cms\LayoutPicker;
5use Apie\Cms\Services\ResponseFactory;
6use Apie\Common\ApieFacade;
7use Apie\Core\BoundedContext\BoundedContextId;
8use Apie\Core\ContextBuilders\ContextBuilderFactory;
9use Apie\Core\ContextConstants;
10use Apie\HtmlBuilders\Factories\ComponentFactory;
11use Psr\Http\Message\ResponseInterface;
12use Psr\Http\Message\ServerRequestInterface;
13use ReflectionClass;
14
15class CreateResourceFormController
16{
17    public function __construct(
18        private readonly ApieFacade $apieFacade,
19        private readonly ComponentFactory $componentFactory,
20        private readonly ContextBuilderFactory $contextBuilderFactory,
21        private readonly ResponseFactory $responseFactory,
22        private readonly LayoutPicker $layoutPicker
23    ) {
24    }
25
26    public function __invoke(ServerRequestInterface $request): ResponseInterface
27    {
28        $context = $this->contextBuilderFactory->createFromRequest($request, [ContextConstants::CMS => true]);
29        $context->checkAuthorization();
30        $action = $this->apieFacade->createAction($context);
31        $class = $action::getInputType(
32            new ReflectionClass($request->getAttribute(ContextConstants::RESOURCE_NAME))
33        );
34        $component = $this->componentFactory->createFormForResourceCreation(
35            'Create ' . $class->getShortName(),
36            $class,
37            new BoundedContextId($request->getAttribute(ContextConstants::BOUNDED_CONTEXT_ID)),
38            $context,
39            $this->layoutPicker->pickLayout($request)
40        );
41        return $this->responseFactory->createComponentPageRender($component, $context);
42    }
43}