src/Application/EventSubscriber/VichPostUploadSubscriber.php line 27

Open in your IDE?
  1. <?php
  2. namespace App\Application\EventSubscriber;
  3. use App\Domain\Entity\Media;
  4. use Liip\ImagineBundle\Message\WarmupCache;
  5. use Symfony\Component\Messenger\MessageBusInterface;
  6. use Vich\UploaderBundle\Event\Event;
  7. /**
  8.  * Class VichPostUploadSubscriber
  9.  * @package App\Application\EventSubscriber
  10.  */
  11. class VichPostUploadSubscriber
  12. {
  13.     /**
  14.      * @param MessageBusInterface $commandBus
  15.      */
  16.     public function __construct(private MessageBusInterface $commandBus)
  17.     {
  18.     }
  19.     /**
  20.      * @param Event $event
  21.      * @return void
  22.      */
  23.     public function onVichUploaderPostUpload(Event $event): void
  24.     {
  25.         /** @var Media $media */
  26.         $media $event->getObject();
  27.         $filePath $media->filePath;
  28.         if ($filePath) {
  29.             $this->commandBus->dispatch(new WarmupCache($filePath));
  30.         }
  31.     }
  32. }