src/Vich/EventSubscriber/MediaUrlResolver.php line 28
<?php
namespace App\Vich\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Vich\UploaderBundle\Event\Events as VichEvents,
Vich\UploaderBundle\Event\Event,
Vich\UploaderBundle\Storage\StorageInterface;
use App\Entity\Interface\UploadableInterface;
final class MediaUrlResolver implements EventSubscriberInterface
{
private StorageInterface $storage;
public function __construct(StorageInterface $storage)
{
$this->storage = $storage;
}
public static function getSubscribedEvents(): array
{
return [
VichEvents::POST_UPLOAD => 'resolve',
];
}
public function resolve(Event $event): void
{
$entity = $event->getObject();
if (! $entity instanceof UploadableInterface) {
return;
}
$entity->setUrl($this->storage->resolveUri($entity, 'file'));
return;
}
}