src/Contact/EventSubscriber/GrantInitialContactAccessSubscriber.php line 48
<?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\ContactCreatedEvent;use App\Contact\Model\ContactInterface;use App\Contact\Service\ContactAccessServiceInterface;use Doctrine\ORM\EntityManagerInterface;use Symfony\Component\EventDispatcher\EventSubscriberInterface;class GrantInitialContactAccessSubscriber implements EventSubscriberInterface{private EntityManagerInterface $entityManager;private ContactAccessServiceInterface $contactAccessService;public function __construct(EntityManagerInterface $entityManager,ContactAccessServiceInterface $contactAccessService) {$this->entityManager = $entityManager;$this->contactAccessService = $contactAccessService;}public static function getSubscribedEvents(): array{return [ContactCreatedEvent::class => 'onContactCreated',];}public function onContactCreated(ContactCreatedEvent $event): void{$contact = $event->getContact();if (ContactInterface::TYPE_PERSON === $contact->getType()) {return;}if (null === $contact->getContactEmail()->getEmail()) {return;}$repository = $this->entityManager->getRepository(ContactInterface::class);$initialAccessor = $repository->findOnePersonByUniqueInformation($contact->getContactEmail()->getEmail());if (null === $initialAccessor) {return;}$this->contactAccessService->grantInitialAccess($contact, $initialAccessor);}}