Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
17 / 17 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| DetailBookController | |
100.00% |
17 / 17 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| index | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | // ╔════════════════════════════════════════════════════════════╗ |
| 4 | // ║ MIT Licence (#Expat) - https://opensource.org/licenses/MIT ║ |
| 5 | // ║ Copyright 2026 Frederic Poeydomenge <dyno@phexium.com> ║ |
| 6 | // ╚════════════════════════════════════════════════════════════╝ |
| 7 | |
| 8 | declare(strict_types=1); |
| 9 | |
| 10 | namespace AppDemo\Library\Application\Http; |
| 11 | |
| 12 | use AppDemo\Library\Application\Query\DetailBookQuery; |
| 13 | use AppDemo\Library\Presentation\DetailBookHtmlPresenter; |
| 14 | use AppDemo\Shared\Application\AbstractHttpController; |
| 15 | use Phexium\Application\ControllerInterface; |
| 16 | use Phexium\Plugin\IdGenerator\Port\IdGeneratorInterface; |
| 17 | use Phexium\Plugin\QueryBus\Port\QueryBusInterface; |
| 18 | use Phexium\Presentation\ResponseBuilderInterface; |
| 19 | use Psr\Http\Message\ResponseInterface; |
| 20 | use Psr\Http\Message\ServerRequestInterface; |
| 21 | use Twig\Environment; |
| 22 | |
| 23 | final readonly class DetailBookController extends AbstractHttpController implements ControllerInterface |
| 24 | { |
| 25 | public function __construct( |
| 26 | private QueryBusInterface $queryBus, |
| 27 | private DetailBookHtmlPresenter $presenter, |
| 28 | private Environment $twig, |
| 29 | private ResponseBuilderInterface $responseBuilder, |
| 30 | private IdGeneratorInterface $idGenerator, |
| 31 | ) {} |
| 32 | |
| 33 | public function index(ServerRequestInterface $request, ResponseInterface $response, array $args = []): ResponseInterface |
| 34 | { |
| 35 | $bookId = $this->idGenerator->from($args['id']); |
| 36 | $query = new DetailBookQuery($bookId); |
| 37 | |
| 38 | $queryResponse = $this->queryBus->dispatch($query); |
| 39 | |
| 40 | $context = $this->createPresentationContext($request); |
| 41 | |
| 42 | $viewModel = $this->presenter |
| 43 | ->withContext($context) |
| 44 | ->present($queryResponse) |
| 45 | ->getViewModel() |
| 46 | ; |
| 47 | |
| 48 | $html = $this->twig->render('DetailBook.html.twig', (array) $viewModel); |
| 49 | |
| 50 | return $this->responseBuilder |
| 51 | ->withResponse($response) |
| 52 | ->withStatus(200) |
| 53 | ->withHtml($html) |
| 54 | ->build() |
| 55 | ; |
| 56 | } |
| 57 | } |