src/Subscriber/Content/ContentVideoMetaSubscriber.php line 42

Open in your IDE?
  1. <?php
  2. namespace App\Subscriber\Content;
  3. use App\Event\Content\ContentVideoMetaStoredEvent;
  4. use App\Event\Content\VideoFileUploadedEvent;
  5. use App\Service\Content\VideoMetaService;
  6. use App\Service\Content\VideoService;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class ContentVideoMetaSubscriber implements EventSubscriberInterface
  9. {
  10.     protected VideoMetaService $service;
  11.     protected VideoService $videoService;
  12.     /**
  13.      * ContentVideoMetaSubscriber constructor.
  14.      */
  15.     public function __construct(VideoMetaService $serviceVideoService $videoService)
  16.     {
  17.         $this->service $service;
  18.         $this->videoService $videoService;
  19.     }
  20.     public static function getSubscribedEvents(): array
  21.     {
  22.         return [
  23.             VideoFileUploadedEvent::class => [
  24.                 ['onVideoUploadedReadMetaData'9998],
  25.             ],
  26.             ContentVideoMetaStoredEvent::class => [
  27.                 ['onVideoMetaStoredUpdateVideoDuration'0],
  28.             ],
  29.         ];
  30.     }
  31.     /**
  32.      * @throws \Doctrine\ORM\ORMException
  33.      * @throws \Doctrine\ORM\OptimisticLockException
  34.      */
  35.     public function onVideoUploadedReadMetaData(VideoFileUploadedEvent $event)
  36.     {
  37.         $video $event->getEntity();
  38.         $meta $this->service->createVideoMeta($video);
  39.         $this->service->storeVideoMeta($meta$video);
  40.     }
  41.     /**
  42.      * @throws \Doctrine\ORM\ORMException
  43.      * @throws \Doctrine\ORM\OptimisticLockException
  44.      */
  45.     public function onVideoMetaStoredUpdateVideoDuration(ContentVideoMetaStoredEvent $event)
  46.     {
  47.         $meta $event->getEntity();
  48.         $video $event->getVideo();
  49.         $video->setDuration($meta->getDuration());
  50.         $this->videoService->storeContentVideo($video);
  51.     }
  52. }