src/EventSubscriber/ScanListenerSubscriber.php line 38

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\Mailer\Event\MessageEvent;
  5. use App\Event\VirusCamp\VirusCampEvent;
  6. use App\Event\VirusCamp\FileInfectedEvent;
  7. use App\Service\DynamicHostService;
  8. use App\Repository\SystemEmailRepository;
  9. use App\Entity\SystemEmail;
  10. use App\Service\NotificationService;
  11. class ScanListenerSubscriber implements EventSubscriberInterface
  12. {
  13.     public function __construct(
  14.         private DynamicHostService $dynamicHostService,
  15.         private SystemEmailRepository $systemEmailRepository
  16.         private NotificationService $notificationService
  17.     ){}
  18.     public function scanFailedEvent(VirusCampEvent $event): void
  19.     {
  20.         $user $event->getFrom();
  21.         $admins $this->dynamicHostService->getMailAdmin();
  22.         $email $this->systemEmailRepository->findOneBy(['code' => SystemEmail::FILE_INFECTED_WITH_VIRUS]);
  23.         $emailAdmin $this->systemEmailRepository->findOneBy(['code' => SystemEmail::FILE_INFECTED_WITH_VIRUS_ADMIN]);
  24.         if (null !== $emailAdmin) {
  25.             foreach ($admins as $admin) {
  26.                  $this->notificationService->create($emailAdmin$admin->value$usernullnullnullnulltrue);
  27.             }
  28.         }
  29.         if (null != $email) {
  30.              $this->notificationService->create($email,$user?->getEmail(), $usernullnullnullnulltrue);
  31.         }
  32.     }
  33.     public function onFileInfected(FileInfectedEvent $event): void
  34.     {
  35.         $user $event->getFrom();
  36.         $file $event->getFile();
  37.         $admins $this->dynamicHostService->getMailAdmin();
  38.         $emailAdmin $this->systemEmailRepository->findOneBy(['code' => SystemEmail::FILE_INFECTED_WITH_VIRUS_ADMIN]);
  39.         if (null !== $emailAdmin) {
  40.             foreach ($admins as $admin) {
  41.                 if(!is_null($file)){
  42.                     if($file instanceof FileMessage){
  43.                         $this->notificationService->create($emailAdmin$admin->value$file?->getMessages()?->getUser(), nullnullnullnulltrue);
  44.                     }else{
  45.                         $this->notificationService->create($emailAdmin$admin->value$file?->getUser(), nullnullnullnulltrue);
  46.                     }
  47.                 }
  48.             }
  49.         }
  50.        
  51.     }
  52.     public static function getSubscribedEvents(): array
  53.     {
  54.         return [
  55.             VirusCampEvent::NAME => 'scanFailedEvent',
  56.             FileInfectedEvent::NAME => 'onFileInfected',
  57.         ];
  58.     }
  59. }