Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
90.00% |
18 / 20 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| SecurityServiceProvider | |
89.47% |
17 / 19 |
|
50.00% |
1 / 2 |
2.00 | |
0.00% |
0 / 1 |
| getDefinitions | |
88.89% |
16 / 18 |
|
0.00% |
0 / 1 |
1.00 | |||
| getExtensions | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 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\Core\Bootstrap\Provider; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | use App\Core\Audit\Application\Service\AuditDataSanitizer; |
| 12 | use App\Core\Audit\Application\Service\SecurityAuditLogger; |
| 13 | use App\Core\Audit\Domain\Repository\SecurityAuditRepositoryInterface; |
| 14 | use App\Core\Audit\Infrastructure\Repository\SqlSecurityAuditRepository; |
| 15 | use App\Modules\User\Infrastructure\Repository\SqlUserRepository; |
| 16 | use App\Modules\User\Infrastructure\Repository\UserIdentityRepository; |
| 17 | use PDO; |
| 18 | use Psr\EventDispatcher\EventDispatcherInterface; |
| 19 | use Yiisoft\Di\ServiceProviderInterface; |
| 20 | use Yiisoft\Security\PasswordHasher; |
| 21 | use Yiisoft\User\CurrentUser; |
| 22 | |
| 23 | /** |
| 24 | * SecurityServiceProvider. |
| 25 | * |
| 26 | * Registers authentication, identity, and security audit services. |
| 27 | * |
| 28 | * @package App\Core\Bootstrap\Provider |
| 29 | */ |
| 30 | final class SecurityServiceProvider implements ServiceProviderInterface |
| 31 | { |
| 32 | /** |
| 33 | * @return array<string, mixed> Definitions mapping for PSR-11 container. |
| 34 | */ |
| 35 | public function getDefinitions(): array |
| 36 | { |
| 37 | return [ |
| 38 | UserIdentityRepository::class => static fn(SqlUserRepository $r): UserIdentityRepository => ( |
| 39 | new UserIdentityRepository($r) |
| 40 | ), |
| 41 | |
| 42 | CurrentUser::class => static fn( |
| 43 | UserIdentityRepository $idRepo, |
| 44 | EventDispatcherInterface $dispatcher |
| 45 | ): CurrentUser => new CurrentUser($idRepo, $dispatcher), |
| 46 | |
| 47 | SecurityAuditRepositoryInterface::class => static fn( |
| 48 | PDO $pdo |
| 49 | ): SecurityAuditRepositoryInterface => new SqlSecurityAuditRepository($pdo), |
| 50 | |
| 51 | SecurityAuditLogger::class => static fn( |
| 52 | SecurityAuditRepositoryInterface $repo |
| 53 | ): SecurityAuditLogger => new SecurityAuditLogger($repo, new AuditDataSanitizer()), |
| 54 | |
| 55 | PasswordHasher::class => static fn(): PasswordHasher => ( |
| 56 | new PasswordHasher(PASSWORD_BCRYPT, ['cost' => 12]) |
| 57 | ), |
| 58 | ]; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * @return array<string, mixed> Service extensions mapping. |
| 63 | */ |
| 64 | public function getExtensions(): array |
| 65 | { |
| 66 | return []; |
| 67 | } |
| 68 | } |