<?php
namespace App\Application\EventSubscriber;
use App\Domain\Entity\Media;
use Liip\ImagineBundle\Message\WarmupCache;
use Symfony\Component\Messenger\MessageBusInterface;
use Vich\UploaderBundle\Event\Event;
/**
* Class VichPostUploadSubscriber
* @package App\Application\EventSubscriber
*/
class VichPostUploadSubscriber
{
/**
* @param MessageBusInterface $commandBus
*/
public function __construct(private MessageBusInterface $commandBus)
{
}
/**
* @param Event $event
* @return void
*/
public function onVichUploaderPostUpload(Event $event): void
{
/** @var Media $media */
$media = $event->getObject();
$filePath = $media->filePath;
if ($filePath) {
$this->commandBus->dispatch(new WarmupCache($filePath));
}
}
}