Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
83.33% covered (warning)
83.33%
5 / 6
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
AbstractHttpController
83.33% covered (warning)
83.33%
5 / 6
66.67% covered (warning)
66.67%
2 / 3
4.07
0.00% covered (danger)
0.00%
0 / 1
 getUserContext
75.00% covered (warning)
75.00%
3 / 4
0.00% covered (danger)
0.00%
0 / 1
2.06
 getUserId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 createPresentationContext
100.00% covered (success)
100.00%
1 / 1
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\Shared\Presentation;
11
12use AppDemo\Shared\Domain\UserContext;
13use Phexium\Domain\Id\IdInterface;
14use Phexium\Presentation\AbstractController;
15use Phexium\Presentation\PresentationContextInterface;
16use Psr\Http\Message\ServerRequestInterface;
17use RuntimeException;
18
19abstract readonly class AbstractHttpController extends AbstractController
20{
21    protected function getUserContext(ServerRequestInterface $request): UserContext
22    {
23        $userContext = $request->getAttribute('user_context');
24
25        if (!$userContext instanceof UserContext) {
26            throw new RuntimeException('No user context found in request.');
27        }
28
29        return $userContext;
30    }
31
32    protected function getUserId(ServerRequestInterface $request): ?IdInterface
33    {
34        return $this->getUserContext($request)->getUserId();
35    }
36
37    protected function createPresentationContext(ServerRequestInterface $request): PresentationContextInterface
38    {
39        return new PresentationContext($this->getUserContext($request));
40    }
41}