Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
90.00% covered (success)
90.00%
18 / 20
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
SecurityServiceProvider
89.47% covered (warning)
89.47%
17 / 19
50.00% covered (danger)
50.00%
1 / 2
2.00
0.00% covered (danger)
0.00%
0 / 1
 getDefinitions
88.89% covered (warning)
88.89%
16 / 18
0.00% covered (danger)
0.00%
0 / 1
1.00
 getExtensions
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5/** @license For full copyright and license information, please see the LICENSE.md file. */
6
7namespace App\Core\Bootstrap\Provider;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11use App\Core\Audit\Application\Service\AuditDataSanitizer;
12use App\Core\Audit\Application\Service\SecurityAuditLogger;
13use App\Core\Audit\Domain\Repository\SecurityAuditRepositoryInterface;
14use App\Core\Audit\Infrastructure\Repository\SqlSecurityAuditRepository;
15use App\Modules\User\Infrastructure\Repository\SqlUserRepository;
16use App\Modules\User\Infrastructure\Repository\UserIdentityRepository;
17use PDO;
18use Psr\EventDispatcher\EventDispatcherInterface;
19use Yiisoft\Di\ServiceProviderInterface;
20use Yiisoft\Security\PasswordHasher;
21use Yiisoft\User\CurrentUser;
22
23/**
24 * SecurityServiceProvider.
25 *
26 * Registers authentication, identity, and security audit services.
27 *
28 * @package App\Core\Bootstrap\Provider
29 */
30final 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}