partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

ImageAttachmentListener.php (716B)


      1 <?php
      2 
      3 namespace PartKeepr\PartBundle\Listeners;
      4 
      5 use Doctrine\ORM\Event\LifecycleEventArgs;
      6 use PartKeepr\ImageBundle\Services\ImageService;
      7 use PartKeepr\PartBundle\Entity\PartAttachment;
      8 
      9 class ImageAttachmentListener
     10 {
     11     private $imageService;
     12 
     13     public function __construct(ImageService $imageService)
     14     {
     15         $this->imageService = $imageService;
     16     }
     17 
     18     public function postLoad(LifecycleEventArgs $event)
     19     {
     20         if ($event->getEntity() instanceof PartAttachment) {
     21             /**
     22              * @var PartAttachment
     23              */
     24             $entity = $event->getEntity();
     25 
     26             $entity->setImage($this->imageService->canHandleMimetype($entity->getMimeType()));
     27         }
     28     }
     29 }