| 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\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\ShowRaaContactInformationOptionChangedEvent; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | use Surfnet\Stepup\Configuration\Event\UseRaLocationsOptionChangedEvent; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | use Surfnet\Stepup\Configuration\Event\VerifyEmailOptionChangedEvent; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | use Surfnet\StepupMiddleware\ApiBundle\Configuration\Entity\InstitutionConfigurationOptions; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | use Surfnet\StepupMiddleware\ApiBundle\Configuration\Repository\AllowedSecondFactorRepository; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | use Surfnet\StepupMiddleware\ApiBundle\Configuration\Repository\InstitutionConfigurationOptionsRepository; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | final class InstitutionConfigurationOptionsProjector extends Projector | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * @var InstitutionConfigurationOptionsRepository | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     private $institutionConfigurationOptionsRepository; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * @var AllowedSecondFactorRepository | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     private $allowedSecondFactorRepository; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     public function __construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         InstitutionConfigurationOptionsRepository $institutionConfigurationOptionsRepository, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         AllowedSecondFactorRepository $allowedSecondFactorRepository | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         $this->institutionConfigurationOptionsRepository = $institutionConfigurationOptionsRepository; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $this->allowedSecondFactorRepository             = $allowedSecondFactorRepository; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     public function applyNewInstitutionConfigurationCreatedEvent(NewInstitutionConfigurationCreatedEvent $event) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $institutionConfigurationOptions = InstitutionConfigurationOptions::create( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             $event->institution, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             $event->useRaLocationsOption, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |             $event->showRaaContactInformationOption, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             $event->verifyEmailOption | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $this->institutionConfigurationOptionsRepository->save($institutionConfigurationOptions); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     public function applyUseRaLocationsOptionChangedEvent(UseRaLocationsOptionChangedEvent $event) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $institutionConfigurationOptions = $this->institutionConfigurationOptionsRepository->findConfigurationOptionsFor($event->institution); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $institutionConfigurationOptions->useRaLocationsOption = $event->useRaLocationsOption; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         $this->institutionConfigurationOptionsRepository->save($institutionConfigurationOptions); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     public function applyShowRaaContactInformationOptionChangedEvent(ShowRaaContactInformationOptionChangedEvent $event) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         $institutionConfigurationOptions = $this->institutionConfigurationOptionsRepository->findConfigurationOptionsFor($event->institution); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $institutionConfigurationOptions->showRaaContactInformationOption = $event->showRaaContactInformationOption; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         $this->institutionConfigurationOptionsRepository->save($institutionConfigurationOptions); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     public function applyVerifyEmailOptionChangedEvent(VerifyEmailOptionChangedEvent $event) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $institutionConfigurationOptions = $this->institutionConfigurationOptionsRepository->findConfigurationOptionsFor($event->institution); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         $institutionConfigurationOptions->verifyEmailOption = $event->verifyEmailOption; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         $this->institutionConfigurationOptionsRepository->save($institutionConfigurationOptions); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 87 |  |  |     public function applyInstitutionConfigurationRemovedEvent(InstitutionConfigurationRemovedEvent $event) | 
            
                                                        
            
                                    
            
            
                | 88 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 89 |  |  |         $this->institutionConfigurationOptionsRepository->removeConfigurationOptionsFor($event->institution); | 
            
                                                        
            
                                    
            
            
                | 90 |  |  |         $this->allowedSecondFactorRepository->clearAllowedSecondFactorListFor($event->institution); | 
            
                                                        
            
                                    
            
            
                | 91 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 92 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 93 |  |  |  | 
            
                        
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.