src/Contact/EventSubscriber/GrantContactPermissionsSubscriber.php line 79
<?phpdeclare(strict_types=1);/*** Copyright (c) 2019 TECLA Consulting Group oü.* All rights reserved.** This unpublished material is proprietary to TECLA Consulting Group oü.* All rights reserved. The methods and* techniques described herein are considered trade secrets* and/or confidential. Reproduction or distribution, in whole* or in part, is forbidden except by express written permission* of TECLA Consulting Group oü.** @author Matúš Sýkorjak <matus@tecla.no>* @copyright 2019 TECLA Consulting Group oü*/namespace App\Contact\EventSubscriber;use App\Contact\Event\ContactAccess;use App\Contact\Event\ContactCreatedEvent;use App\Contact\Event\ContactRelationshipCompanyContactPerson;use App\Contact\Event\Relationship\Employment;use App\Contact\Event\Relationship\Ownership;use App\Contact\Security\ContactContextInterface;use App\Contact\Service\ContactPermissionService;use Symfony\Component\EventDispatcher\EventSubscriberInterface;class GrantContactPermissionsSubscriber implements EventSubscriberInterface{private ContactContextInterface $contactContext;private ContactPermissionService $contactPermissionService;public function __construct(ContactContextInterface $contactContext,ContactPermissionService $contactPermissionService) {$this->contactContext = $contactContext;$this->contactPermissionService = $contactPermissionService;}public static function getSubscribedEvents(): array{return [ContactCreatedEvent::class => 'onContactCreated',ContactAccess\CreatedEvent::class => 'onAccessCreated',ContactRelationshipCompanyContactPerson\CreatedEvent::class => 'onContactPersonCreated',Employment\CreatedEvent::class => 'onEmploymentCreated',Ownership\CreatedEvent::class => 'onOwnershipCreated',Ownership\UpdatedEvent::class => 'onOwnershipUpdated',];}public function onContactCreated(ContactCreatedEvent $event): void{$this->contactPermissionService->grantPermission($event->getContact(),$this->contactContext->getCurrent());}public function onAccessCreated(ContactAccess\CreatedEvent $event): void{$access = $event->getContactAccess();$this->contactPermissionService->grantPermission($access->getContact(),$access->getAccessor());$this->contactPermissionService->grantPermission($access->getAccessor(),$access->getContact());}public function onContactPersonCreated(ContactRelationshipCompanyContactPerson\CreatedEvent $event): void{$relationship = $event->getRelationship();$this->contactPermissionService->grantPermission($relationship->getContactPerson(),$relationship->getCompany());}public function onEmploymentCreated(Employment\CreatedEvent $event): void{$relationship = $event->getRelationship();$this->contactPermissionService->grantPermission($relationship->getEmployee(),$relationship->getEmployer());}public function onOwnershipCreated(Ownership\CreatedEvent $event): void{$relationship = $event->getRelationship();$this->contactPermissionService->grantPermission($relationship->getOwner(),$relationship->getCompany());}public function onOwnershipUpdated(Ownership\UpdatedEvent $event): void{$relationship = $event->getRelationship();$this->contactPermissionService->grantPermission($relationship->getOwner(),$relationship->getCompany());}}