Completed
Pull Request — develop (#236)
by
unknown
06:38 queued 03:11
created

applyNewInstitutionConfigurationCreatedEvent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * Copyright 2018 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\Projector;
20
21
use Broadway\ReadModel\Projector;
22
use Surfnet\Stepup\Configuration\Event\InstitutionConfigurationRemovedEvent;
23
use Surfnet\Stepup\Configuration\Event\NewInstitutionConfigurationCreatedEvent;
24
use Surfnet\Stepup\Configuration\Event\SelectRaaOptionChangedEvent;
25
use Surfnet\Stepup\Configuration\Event\UseRaaOptionChangedEvent;
26
use Surfnet\Stepup\Configuration\Event\UseRaOptionChangedEvent;
27
use Surfnet\Stepup\Configuration\Value\InstitutionAuthorizationOption;
28
use Surfnet\Stepup\Configuration\Value\InstitutionRole;
29
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Repository\InstitutionAuthorizationRepository;
30
31
final class InstitutionAuthorizationProjector extends Projector
32
{
33
    /**
34
     * @var InstitutionAuthorizationRepository
35
     */
36
    private $institutionAuthorizationRepository;
37
38
    public function __construct(
39
        InstitutionAuthorizationRepository $institutionAuthorizationRepository
40
    ) {
41
        $this->institutionAuthorizationRepository = $institutionAuthorizationRepository;
42
    }
43
44
    public function applyNewInstitutionConfigurationCreatedEvent(NewInstitutionConfigurationCreatedEvent $event)
45
    {
46
        $this->institutionAuthorizationRepository->saveInstitutionOption(
47
            $event->institution,
48
            InstitutionAuthorizationOption::getDefault(InstitutionRole::useRa())
49
        );
50
        $this->institutionAuthorizationRepository->saveInstitutionOption(
51
            $event->institution,
52
            InstitutionAuthorizationOption::getDefault(InstitutionRole::useRaa())
53
        );
54
        $this->institutionAuthorizationRepository->saveInstitutionOption(
55
            $event->institution,
56
            InstitutionAuthorizationOption::getDefault(InstitutionRole::selectRaa())
57
        );
58
    }
59
60
    public function applyUseRaOptionChangedEvent(UseRaOptionChangedEvent $event)
61
    {
62
        $this->institutionAuthorizationRepository->saveInstitutionOption(
63
            $event->institution,
64
            $event->useRaOption
65
        );
66
    }
67
68
    public function applyUseRaaOptionChangedEvent(UseRaaOptionChangedEvent $event)
69
    {
70
        $this->institutionAuthorizationRepository->saveInstitutionOption(
71
            $event->institution,
72
            $event->useRaaOption
73
        );
74
    }
75
76
    public function applySelectRaaOptionChangedEvent(SelectRaaOptionChangedEvent $event)
77
    {
78
        $this->institutionAuthorizationRepository->saveInstitutionOption(
79
            $event->institution,
80
            $event->selectRaaOption
81
        );
82
    }
83
84
    public function applyInstitutionConfigurationRemovedEvent(InstitutionConfigurationRemovedEvent $event)
85
    {
86
        $this->institutionAuthorizationRepository->clearInstitutionOption(
87
            $event->institution
88
        );
89
    }
90
}
91