src/EventSubscriber/VOD/ExportGenerator/FileHandlerSubscriber.php line 42

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber\VOD\ExportGenerator;
  3. use App\Contract\VOD\ExportFileHandler\FileHandlerInterface;
  4. use App\Event\VOD\ExportGenerator\ExportEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. class FileHandlerSubscriber implements EventSubscriberInterface
  7. {
  8.     /**
  9.      * The custom file handler service responsible for copying the file in specified location.
  10.      *
  11.      * @var \App\Contract\VOD\ExportFileHandler\FileHandlerInterface
  12.      */
  13.     private $fileHandler;
  14.     public function __construct(FileHandlerInterface $fileHandler)
  15.     {
  16.         $this->fileHandler $fileHandler;
  17.     }
  18.     public static function getSubscribedEvents(): array
  19.     {
  20.         return [
  21.             ExportEvent::class => 'onExportFileGenerated',
  22.         ];
  23.     }
  24.     /**
  25.      * Public callback for the export event.
  26.      *
  27.      * Responsible for moving the generated file to given location, based on the environment.
  28.      * For the local/dev environment, the NullHandler will be used, so the file won't be
  29.      * copied anywhere, but for production, we will use the AwsHandler in order to copy
  30.      * the file in a dedicated bucket.
  31.      *
  32.      * @param \App\Event\VOD\ExportGenerator\ExportEvent $event
  33.      *   The instance of the dispatched event
  34.      */
  35.     public function onExportFileGenerated(ExportEvent $event): void
  36.     {
  37.         $this->fileHandler->processEntity($event->getEntity());
  38.     }
  39. }