1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Modules\Security\Domain; |
4
|
|
|
|
5
|
|
|
use App\Infrastructure\Events\Api\ApplicationEventPublisherInterface; |
6
|
|
|
use App\Infrastructure\Events\Api\ApplicationEventSubscriber; |
7
|
|
|
use App\Infrastructure\Events\Api\EventHandlerReference; |
8
|
|
|
use App\Infrastructure\Security\LoggedInUserProviderInterface; |
9
|
|
|
use App\Modules\Security\Api\Event\Inbound\CommentsCountUpdatedSecurityIEvent; |
10
|
|
|
use App\Modules\Security\Api\Event\Inbound\PostCreatedSecurityIEvent; |
11
|
|
|
use App\Modules\Security\Api\Event\Inbound\PostDeletedSecurityIEvent; |
12
|
|
|
use App\Modules\Security\Api\Event\Inbound\PostUpdatedSecurityIEvent; |
13
|
|
|
use App\Modules\Security\Api\SecurityApiInterface; |
14
|
|
|
use App\Modules\Security\Domain\Logic\CommentsEventsHandler; |
15
|
|
|
use App\Modules\Security\Domain\Logic\JWTSecurityListener; |
16
|
|
|
use App\Modules\Security\Domain\Logic\PostHeadersFinder; |
17
|
|
|
use App\Modules\Security\Domain\Logic\PostsEventsHandler; |
18
|
|
|
use App\Modules\Security\Domain\Logic\SecurityValidator; |
19
|
|
|
use App\Modules\Security\Domain\Logic\UserCreator; |
20
|
|
|
use App\Modules\Security\Domain\Logic\UserUpdater; |
21
|
|
|
use App\Modules\Security\Domain\Repository\SecurityCommentsEventHandlingRepositoryInterface; |
22
|
|
|
use App\Modules\Security\Domain\Repository\SecurityPostEventsHandlingRepositoryInterface; |
23
|
|
|
use App\Modules\Security\Domain\Repository\UserCreationRepositoryInterface; |
24
|
|
|
use App\Modules\Security\Domain\Repository\UserFindingRepositoryInterface; |
25
|
|
|
use App\Modules\Security\Domain\Repository\UserPostHeadersFindingRepositoryInterface; |
26
|
|
|
use App\Modules\Security\Domain\Repository\UserUpdatingRepositoryInterface; |
27
|
|
|
use App\Modules\Security\Domain\Transactions\SecurityTransactionFactoryInterface; |
28
|
|
|
use Psr\Log\LoggerInterface; |
29
|
|
|
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; |
30
|
|
|
use Symfony\Component\Validator\Validator\ValidatorInterface; |
31
|
|
|
|
32
|
|
|
class SecurityApi extends ApplicationEventSubscriber implements SecurityApiInterface |
33
|
|
|
{ |
34
|
|
|
use UserCreator { |
35
|
|
|
UserCreator::__construct as __userCreatorConstruct; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
use UserUpdater { |
39
|
|
|
UserUpdater::__construct as __userUpdaterConstruct; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
use JWTSecurityListener { |
|
|
|
|
43
|
|
|
JWTSecurityListener::__construct as __jwtTokenDecoratorConstruct; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
use PostsEventsHandler { |
47
|
|
|
PostsEventsHandler::__construct as __postEventsHandlerConstruct; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
use CommentsEventsHandler { |
51
|
|
|
CommentsEventsHandler::__construct as __commentsEventsHandlerConstruct; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
use PostHeadersFinder { |
55
|
|
|
PostHeadersFinder::__construct as __postHeadersFinderConstruct; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param SecurityTransactionFactoryInterface $transactionFactory |
61
|
|
|
* @param UserPasswordHasherInterface $passwordHasher |
62
|
|
|
* @param UserCreationRepositoryInterface $creationRepository |
63
|
|
|
* @param LoggedInUserProviderInterface $databaseLoggedInUserProvider |
64
|
|
|
* @param SecurityPostEventsHandlingRepositoryInterface $postEventsSecurityRepository |
65
|
|
|
* @param UserPostHeadersFindingRepositoryInterface $headersFindingRepository |
66
|
|
|
* @param SecurityCommentsEventHandlingRepositoryInterface $commentsEventHandlingRepository |
67
|
|
|
* @param LoggerInterface $logger |
68
|
|
|
*/ |
69
|
|
|
public function __construct( |
70
|
|
|
SecurityTransactionFactoryInterface $transactionFactory, |
71
|
|
|
UserPasswordHasherInterface $passwordHasher, |
72
|
|
|
UserCreationRepositoryInterface $creationRepository, |
73
|
|
|
LoggedInUserProviderInterface $databaseLoggedInUserProvider, |
74
|
|
|
SecurityPostEventsHandlingRepositoryInterface $postEventsSecurityRepository, |
75
|
|
|
UserPostHeadersFindingRepositoryInterface $headersFindingRepository, |
76
|
|
|
SecurityCommentsEventHandlingRepositoryInterface $commentsEventHandlingRepository, |
77
|
|
|
UserUpdatingRepositoryInterface $updatingRepository, |
78
|
|
|
UserFindingRepositoryInterface $findingRepository, |
79
|
|
|
LoggerInterface $logger, |
80
|
|
|
ValidatorInterface $validator, |
81
|
|
|
ApplicationEventPublisherInterface $eventPublisher |
82
|
|
|
) |
83
|
|
|
{ |
84
|
|
|
parent::__construct($logger); |
|
|
|
|
85
|
|
|
$securityValidator = new SecurityValidator($validator, $findingRepository); |
86
|
|
|
$this->__userUpdaterConstruct($eventPublisher, $transactionFactory, $updatingRepository, $securityValidator, $passwordHasher); |
87
|
|
|
$this->__userCreatorConstruct($passwordHasher, $transactionFactory, $creationRepository, $securityValidator); |
88
|
|
|
$this->__jwtTokenDecoratorConstruct($databaseLoggedInUserProvider); |
89
|
|
|
$this->__postEventsHandlerConstruct($transactionFactory, $postEventsSecurityRepository); |
90
|
|
|
$this->__postHeadersFinderConstruct($headersFindingRepository); |
91
|
|
|
$this->__commentsEventsHandlerConstruct($transactionFactory, $commentsEventHandlingRepository); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return array<string, EventHandlerReference> |
96
|
|
|
*/ |
97
|
|
|
protected function subscribe(): array |
98
|
|
|
{ |
99
|
|
|
return [ |
100
|
|
|
PostCreatedSecurityIEvent::EVENT_NAME => EventHandlerReference::create('onPostCreated', PostCreatedSecurityIEvent::class), |
101
|
|
|
PostUpdatedSecurityIEvent::EVENT_NAME => EventHandlerReference::create('onPostUpdated', PostUpdatedSecurityIEvent::class), |
102
|
|
|
PostDeletedSecurityIEvent::EVENT_NAME => EventHandlerReference::create('onPostDeleted', PostDeletedSecurityIEvent::class), |
103
|
|
|
CommentsCountUpdatedSecurityIEvent::EVENT_NAME => EventHandlerReference::create('onCommentsCountUpdated', CommentsCountUpdatedSecurityIEvent::class), |
104
|
|
|
]; |
105
|
|
|
} |
106
|
|
|
} |