Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
DetailBookController
100.00% covered (success)
100.00%
17 / 17
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
 index
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
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
8declare(strict_types=1);
9
10namespace AppDemo\Library\Application\Http;
11
12use AppDemo\Library\Application\Query\DetailBookQuery;
13use AppDemo\Library\Presentation\DetailBookHtmlPresenter;
14use AppDemo\Shared\Application\AbstractHttpController;
15use Phexium\Application\ControllerInterface;
16use Phexium\Plugin\IdGenerator\Port\IdGeneratorInterface;
17use Phexium\Plugin\QueryBus\Port\QueryBusInterface;
18use Phexium\Presentation\ResponseBuilderInterface;
19use Psr\Http\Message\ResponseInterface;
20use Psr\Http\Message\ServerRequestInterface;
21use Twig\Environment;
22
23final 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}