1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2016 SURFnet B.V. |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Surfnet\StepupMiddleware\ApiBundle\Configuration\EventListener; |
20
|
|
|
|
21
|
|
|
use Broadway\Domain\DomainMessage; |
22
|
|
|
use Broadway\EventHandling\EventListenerInterface; |
23
|
|
|
use Rhumsaa\Uuid\Uuid; |
24
|
|
|
use Surfnet\Stepup\Configuration\Value\Institution; |
25
|
|
|
use Surfnet\Stepup\Identity\Event\IdentityCreatedEvent; |
26
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Repository\ConfiguredInstitutionRepository; |
27
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Command\CreateInstitutionConfigurationCommand; |
28
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Pipeline\Pipeline; |
29
|
|
|
|
30
|
|
|
final class IdentityEventListener implements EventListenerInterface |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* @var ConfiguredInstitutionRepository |
34
|
|
|
*/ |
35
|
|
|
private $configuredInstitutionRepository; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var Pipeline |
39
|
|
|
*/ |
40
|
|
|
private $pipeline; |
41
|
|
|
|
42
|
|
|
public function __construct(ConfiguredInstitutionRepository $configuredInstitutionRepository, Pipeline $pipeline) |
|
|
|
|
43
|
|
|
{ |
44
|
|
|
$this->configuredInstitutionRepository = $configuredInstitutionRepository; |
45
|
|
|
$this->pipeline = $pipeline; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param DomainMessage $domainMessage |
50
|
|
|
*/ |
51
|
|
View Code Duplication |
public function handle(DomainMessage $domainMessage) |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
$event = $domainMessage->getPayload(); |
54
|
|
|
|
55
|
|
|
$classParts = explode('\\', get_class($event)); |
56
|
|
|
$method = 'apply' . end($classParts); |
57
|
|
|
|
58
|
|
|
if (!method_exists($this, $method)) { |
59
|
|
|
return; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$this->$method($event, $domainMessage); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function applyIdentityCreatedEvent(IdentityCreatedEvent $event) |
66
|
|
|
{ |
67
|
|
|
$institution = new Institution($event->identityInstitution->getInstitution()); |
68
|
|
|
|
69
|
|
|
if ($this->configuredInstitutionRepository->hasConfigurationFor($institution)) { |
70
|
|
|
return; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$command = new CreateInstitutionConfigurationCommand(); |
74
|
|
|
$command->UUID = (string) Uuid::uuid4(); |
75
|
|
|
$command->institution = $institution; |
|
|
|
|
76
|
|
|
|
77
|
|
|
$this->pipeline->process($command); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.