Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| LastActionResultController | |
0.00% |
0 / 16 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| __invoke | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | namespace Apie\Cms\Controllers; |
| 3 | |
| 4 | use Apie\Cms\Services\ResponseFactory; |
| 5 | use Apie\Core\BoundedContext\BoundedContextId; |
| 6 | use Apie\Core\ContextBuilders\ContextBuilderFactory; |
| 7 | use Apie\Core\ContextConstants; |
| 8 | use Apie\HtmlBuilders\Factories\ComponentFactory; |
| 9 | use Apie\HtmlBuilders\Factories\FieldDisplayComponentFactory; |
| 10 | use Psr\Http\Message\ResponseInterface; |
| 11 | use Psr\Http\Message\ServerRequestInterface; |
| 12 | use Symfony\Component\HttpFoundation\Session\SessionInterface; |
| 13 | |
| 14 | class LastActionResultController |
| 15 | { |
| 16 | public function __construct( |
| 17 | private readonly ComponentFactory $componentFactory, |
| 18 | private readonly ContextBuilderFactory $contextBuilder, |
| 19 | private readonly ResponseFactory $responseFactory, |
| 20 | private readonly FieldDisplayComponentFactory $fieldDisplayComponentFactory |
| 21 | ) { |
| 22 | } |
| 23 | |
| 24 | public function __invoke(ServerRequestInterface $request): ResponseInterface |
| 25 | { |
| 26 | $context = $this->contextBuilder->createFromRequest($request, [ContextConstants::CMS => true]); |
| 27 | $boundedContextId = new BoundedContextId($request->getAttribute('boundedContextId')); |
| 28 | $id = $request->getAttribute('id'); |
| 29 | $session = $context->getContext(SessionInterface::class); |
| 30 | $actionResults = $session->get('_output_results', []); |
| 31 | if (array_key_exists($id, $actionResults)) { |
| 32 | $component = $this->componentFactory->createWrapLayout( |
| 33 | 'Action result', |
| 34 | $boundedContextId, |
| 35 | $context, |
| 36 | $this->fieldDisplayComponentFactory->createDisplayFor($actionResults[$id], $context) |
| 37 | ); |
| 38 | return $this->responseFactory->createComponentPageRender($component, $context); |
| 39 | } |
| 40 | $redirectUrl = (string) $request->getUri() . '/../../'; |
| 41 | return $this->responseFactory->createRedirect($redirectUrl, $context); |
| 42 | } |
| 43 | } |