vendor/vich/uploader-bundle/src/EventListener/Doctrine/InjectListener.php line 37

Open in your IDE?
  1. <?php
  2. namespace Vich\UploaderBundle\EventListener\Doctrine;
  3. use Doctrine\Persistence\Event\LifecycleEventArgs;
  4. /**
  5.  * InjectListener.
  6.  *
  7.  * Listen to the load event in order to inject File objects.
  8.  *
  9.  * @author Kévin Gomez <contact@kevingomez.fr>
  10.  */
  11. class InjectListener extends BaseListener
  12. {
  13.     /**
  14.      * The events the listener is subscribed to.
  15.      *
  16.      * @return array The array of events
  17.      */
  18.     public function getSubscribedEvents(): array
  19.     {
  20.         return [
  21.             'postLoad',
  22.         ];
  23.     }
  24.     /**
  25.      * @param LifecycleEventArgs $event The event
  26.      *
  27.      * @throws \Vich\UploaderBundle\Exception\MappingNotFoundException
  28.      */
  29.     public function postLoad(LifecycleEventArgs $event): void
  30.     {
  31.         $object $event->getObject();
  32.         if (!$this->isUploadable($object)) {
  33.             return;
  34.         }
  35.         foreach ($this->getUploadableFields($object) as $field) {
  36.             $this->handler->inject($object$field);
  37.         }
  38.     }
  39. }