vendor/crehler/image-booster/src/Subscriber/MediaBoosterGeneratorSubscriber.php line 29

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Crehler\ImageBooster\Subscriber;
  3. use Crehler\ImageBooster\Event\MediaBoosterGenerateEvent;
  4. use Crehler\ImageBooster\Service\MediaBoosterService;
  5. use Crehler\ImageBooster\Service\WatermarkService;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityWrittenEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class MediaBoosterGeneratorSubscriber implements EventSubscriberInterface
  9. {
  10.     private WatermarkService $watermarkSevice;
  11.     public function __construct(
  12.         WatermarkService $watermarkSevice
  13.     )
  14.     {
  15.         $this->watermarkSevice $watermarkSevice;
  16.     }
  17.     public static function getSubscribedEvents(): array
  18.     {
  19.         return [
  20.             'crehler.image_booster.generate_media' => ['generateMediaBooster']
  21.         ];
  22.     }
  23.     public function generateMediaBooster(EntityWrittenEvent $event)
  24.     {
  25.         foreach ($event->getWriteResults() as $result) {
  26.             if (isset($result->getPayload()['mediaId'])) {
  27.                 $this->watermarkSevice->appendWatermark($result->getPayload()['mediaId']);
  28.             }
  29.         }
  30.     }
  31. }