Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| UserIdentityRepository | |
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| findIdentity | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** @license For full copyright and license information, please see the LICENSE.md file. */ |
| 6 | |
| 7 | namespace App\Modules\User\Infrastructure\Repository; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | use App\Modules\User\Domain\Repository\UserRepositoryInterface; |
| 12 | use App\Modules\User\Presentation\Web\Identity; |
| 13 | use Yiisoft\Auth\IdentityInterface; |
| 14 | use Yiisoft\Auth\IdentityRepositoryInterface; |
| 15 | |
| 16 | /** |
| 17 | * User Identity Repository. |
| 18 | * |
| 19 | * Provides identity resolution for Yii3 User component via UserRepositoryInterface. |
| 20 | * |
| 21 | * @package App\Modules\User\Infrastructure\Repository |
| 22 | */ |
| 23 | final readonly class UserIdentityRepository implements IdentityRepositoryInterface |
| 24 | { |
| 25 | /** |
| 26 | * UserIdentityRepository constructor. |
| 27 | * |
| 28 | * @param UserRepositoryInterface $userRepository Underlying user repository contract. |
| 29 | */ |
| 30 | public function __construct( |
| 31 | private UserRepositoryInterface $userRepository, |
| 32 | ) { |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Finds identity by its identifier. |
| 37 | * |
| 38 | * @param string $id Identity identifier (user ID). |
| 39 | * |
| 40 | * @return IdentityInterface|null Identity instance or null if not found. |
| 41 | */ |
| 42 | public function findIdentity(string $id): ?IdentityInterface |
| 43 | { |
| 44 | $user = $this->userRepository->findById((int) $id); |
| 45 | |
| 46 | return $user !== null ? new Identity($user->getId(), $user->getLocale()) : null; |
| 47 | } |
| 48 | } |