Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
17 / 17 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| RemoveResourceFormController | |
100.00% |
17 / 17 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __invoke | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Apie\Cms\Controllers; |
| 3 | |
| 4 | use Apie\Cms\LayoutPicker; |
| 5 | use Apie\Cms\Services\ResponseFactory; |
| 6 | use Apie\Common\ApieFacade; |
| 7 | use Apie\Core\BoundedContext\BoundedContextId; |
| 8 | use Apie\Core\ContextBuilders\ContextBuilderFactory; |
| 9 | use Apie\Core\ContextConstants; |
| 10 | use Apie\HtmlBuilders\Factories\ComponentFactory; |
| 11 | use Psr\Http\Message\ResponseInterface; |
| 12 | use Psr\Http\Message\ServerRequestInterface; |
| 13 | use ReflectionClass; |
| 14 | |
| 15 | class RemoveResourceFormController |
| 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->createFormForResourceRemoval( |
| 35 | 'Remove ' . $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 | ->withHeader('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0') |
| 43 | ->withHeader('Pragma', 'no-cache'); |
| 44 | ; |
| 45 | } |
| 46 | } |