src/App/VideoProcessing/Processing/FeedVideoPopProcessing.php line 25

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace App\VideoProcessing\Processing;
  3. use App\Entity\Feed;
  4. use App\Entity\ShopVideoFile;
  5. use App\RabbitMq\Processing\PopProcessingEvent;
  6. use App\VideoProcessing\Ffmpeg\FileInfo\FetcherInterface;
  7. use InvalidArgumentException;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use UploadsBundle\RabbitMq\Handler\FileHandlerFactoryHandler;
  10. class FeedVideoPopProcessing implements EventSubscriberInterface
  11. {
  12.     private FetcherInterface $fetcher;
  13.     private bool $enabled true;
  14.     public function __construct(FetcherInterface $fetcher)
  15.     {
  16.         $this->fetcher $fetcher;
  17.     }
  18.     public function onPop(PopProcessingEvent $event): void
  19.     {
  20.         if (!$this->isEnabled()) {
  21.             return;
  22.         }
  23.         if ($event->getService() !== FileHandlerFactoryHandler::HANDLER) {
  24.             return;
  25.         }
  26.         /** @var string[] $arguments */
  27.         $arguments $event->getArguments();
  28.         if (!isset($arguments[0]) || $arguments[0] !== 'feed_trailer') {
  29.             return;
  30.         }
  31.         if ($event->getMethod() !== 'move' && $event->getMethod() !== 'create') {
  32.             return;
  33.         }
  34.         if (!isset($arguments[1], $arguments[2])) {
  35.             throw new InvalidArgumentException('Can not use class without file paths.');
  36.         }
  37.         /** @var Feed $feed */
  38.         $feed $event->getEntity();
  39.         $videoFile = new ShopVideoFile();
  40.         $this->fetcher->getFileInfo($videoFile$arguments[1], $arguments[2]);
  41.         $feed->setVideoWidth($videoFile->getWidth());
  42.         $feed->setVideoHeight($videoFile->getHeight());
  43.         if (null === $runtime $videoFile->getRunTime()) {
  44.             return;
  45.         }
  46.         $feed->setVideoRunTime($runtime);
  47.     }
  48.     private function isEnabled(): bool
  49.     {
  50.         return $this->enabled;
  51.     }
  52.     public function setEnabled(bool $enabled): void
  53.     {
  54.         $this->enabled $enabled;
  55.     }
  56.     /**
  57.      * @return array<string, array<int|string, array<int|string, int|string>|int|string>|string>
  58.      */
  59.     public static function getSubscribedEvents(): array
  60.     {
  61.         return [
  62.             PopProcessingEvent::class => 'onPop',
  63.         ];
  64.     }
  65. }