Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ListBooksController
100.00% covered (success)
100.00%
16 / 16
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%
15 / 15
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\ListBooksQuery;
13use AppDemo\Library\Presentation\ListBooksHtmlPresenter;
14use AppDemo\Shared\Application\AbstractHttpController;
15use Phexium\Application\ControllerInterface;
16use Phexium\Plugin\QueryBus\Port\QueryBusInterface;
17use Phexium\Presentation\ResponseBuilderInterface;
18use Psr\Http\Message\ResponseInterface;
19use Psr\Http\Message\ServerRequestInterface;
20use Twig\Environment;
21
22final readonly class ListBooksController extends AbstractHttpController implements ControllerInterface
23{
24    public function __construct(
25        private QueryBusInterface $queryBus,
26        private ListBooksHtmlPresenter $presenter,
27        private Environment $twig,
28        private ResponseBuilderInterface $responseBuilder,
29    ) {}
30
31    public function index(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
32    {
33        $query = new ListBooksQuery();
34        $queryResponse = $this->queryBus->dispatch($query);
35
36        $context = $this->createPresentationContext($request);
37
38        $viewModel = $this->presenter
39            ->withContext($context)
40            ->present($queryResponse)
41            ->getViewModel()
42        ;
43        $html = $this->twig->render('ListBooks.html.twig', (array) $viewModel);
44
45        return $this->responseBuilder
46            ->withResponse($response)
47            ->withStatus(200)
48            ->withHtml($html)
49            ->build()
50        ;
51    }
52}