src/Note/EventSubscriber/RevokePermissionSubscriber.php line 47

  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * Copyright (c) 2023 TECLA Consulting Group oü.
  5.  * All rights reserved.
  6.  *
  7.  * This unpublished material is proprietary to TECLA Consulting Group oü.
  8.  * All rights reserved. The methods and
  9.  * techniques described herein are considered trade secrets
  10.  * and/or confidential. Reproduction or distribution, in whole
  11.  * or in part, is forbidden except by express written permission
  12.  * of TECLA Consulting Group oü.
  13.  *
  14.  * @author    Matúš Sýkorjak <matus@tecla.no>
  15.  * @copyright 2023 TECLA Consulting Group oü
  16.  */
  17. namespace App\Note\EventSubscriber;
  18. use App\Note\Event\Note\DeleteEvent;
  19. use App\Note\Query\NotePermission\FindAllByNoteQueryInterface;
  20. use App\Note\Service\NotePermissionServiceInterface;
  21. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  22. final class RevokePermissionSubscriber implements EventSubscriberInterface
  23. {
  24.     private FindAllByNoteQueryInterface $findAllQuery;
  25.     private NotePermissionServiceInterface $notePermissionService;
  26.     public function __construct(
  27.         FindAllByNoteQueryInterface $findAllQuery,
  28.         NotePermissionServiceInterface $notePermissionService
  29.     ) {
  30.         $this->findAllQuery $findAllQuery;
  31.         $this->notePermissionService $notePermissionService;
  32.     }
  33.     public static function getSubscribedEvents(): array
  34.     {
  35.         return [
  36.             DeleteEvent::class => 'onDeleteEvent',
  37.         ];
  38.     }
  39.     public function onDeleteEvent(DeleteEvent $event): void
  40.     {
  41.         $permissions $this->findAllQuery->execute($event->getNote());
  42.         $this->notePermissionService->deleteCollection($permissions);
  43.     }
  44. }