Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| UserContextProvider | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getCurrentUserContext | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| 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\Shared\Application\Service; |
| 11 | |
| 12 | use AppDemo\Shared\Domain\Interface\RbacPermissionServiceInterface; |
| 13 | use AppDemo\Shared\Domain\Interface\SessionServiceInterface; |
| 14 | use AppDemo\Shared\Domain\Interface\UserContextProviderInterface; |
| 15 | use AppDemo\Shared\Domain\UserContext; |
| 16 | use AppDemo\User\Domain\UserRepository; |
| 17 | use Phexium\Domain\Id\IdInterface; |
| 18 | |
| 19 | final readonly class UserContextProvider implements UserContextProviderInterface |
| 20 | { |
| 21 | public function __construct( |
| 22 | private SessionServiceInterface $sessionService, |
| 23 | private UserRepository $userRepository, |
| 24 | private RbacPermissionServiceInterface $rbacService |
| 25 | ) {} |
| 26 | |
| 27 | public function getCurrentUserContext(): UserContext |
| 28 | { |
| 29 | $user = null; |
| 30 | $userId = $this->sessionService->getUserId(); |
| 31 | |
| 32 | if ($userId instanceof IdInterface) { |
| 33 | $user = $this->userRepository->findById($userId); |
| 34 | } |
| 35 | |
| 36 | return new UserContext($user, $this->rbacService); |
| 37 | } |
| 38 | } |