src/Contact/EventSubscriber/DeleteContactFromGroupsSubscriber.php line 52
<?phpdeclare(strict_types=1);/*** Copyright (c) 2023 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 2023 TECLA Consulting Group oü*/namespace App\Contact\EventSubscriber;use App\Contact\Event\ContactDeletedEvent;use App\Contact\Query\GroupItem\FindAllByContactQueryInterface;use App\Contact\Security\ContactContextInterface;use App\Contact\Service\GroupItemServiceInterface;use Symfony\Component\EventDispatcher\EventSubscriberInterface;final class DeleteContactFromGroupsSubscriber implements EventSubscriberInterface{private ContactContextInterface $contactContext;private FindAllByContactQueryInterface $findAllByContactQuery;private GroupItemServiceInterface $itemService;public function __construct(ContactContextInterface $contactContext,FindAllByContactQueryInterface $findAllByContactQuery,GroupItemServiceInterface $itemService) {$this->contactContext = $contactContext;$this->findAllByContactQuery = $findAllByContactQuery;$this->itemService = $itemService;}public static function getSubscribedEvents(): array{return [ContactDeletedEvent::class => 'onContactDeletedEvent',];}public function onContactDeletedEvent(ContactDeletedEvent $event): void{$currentContext = $this->contactContext->getCurrent();if (null === $currentContext) {return;}$contact = $event->getContact();$groupItems = $this->findAllByContactQuery->execute($currentContext, $contact);foreach ($groupItems as $groupItem) {$this->itemService->delete($groupItem);}}}