-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserRepository.php
More file actions
43 lines (33 loc) · 1.13 KB
/
UserRepository.php
File metadata and controls
43 lines (33 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
/**
* Copyright © . All rights reserved.
* See LICENSE file for license details.
*/
declare(strict_types=1);
namespace OxidEsales\ExamplesModule\Greeting\Infrastructure\Repository;
use OxidEsales\ExamplesModule\Extension\Model\User;
use OxidEsales\ExamplesModule\Greeting\Exception\UserNotLoggedIn;
use OxidEsales\ExamplesModule\Greeting\Infrastructure\Factory\UserModelFactoryInterface;
use OxidEsales\ExamplesModule\Greeting\Model\PersonalGreetingUserInterface;
readonly class UserRepository implements UserRepositoryInterface
{
public function __construct(
private UserModelFactoryInterface $userModelFactory,
) {
}
public function getUserById(string $userId): PersonalGreetingUserInterface
{
$userModel = $this->userModelFactory->create();
$userModel->load($userId);
return $userModel;
}
public function getActiveUser(): User
{
$userModel = $this->userModelFactory->create();
$loadingSuccessful = $userModel->loadActiveUser();
if (!$loadingSuccessful) {
throw new UserNotLoggedIn();
}
return $userModel;
}
}