<?php declare(strict_types=1);
namespace Crehler\ImageBooster\Subscriber;
use Crehler\ImageBooster\Event\MediaBoosterGenerateEvent;
use Crehler\ImageBooster\Service\MediaBoosterService;
use Crehler\ImageBooster\Service\WatermarkService;
use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityWrittenEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class MediaBoosterGeneratorSubscriber implements EventSubscriberInterface
{
private WatermarkService $watermarkSevice;
public function __construct(
WatermarkService $watermarkSevice
)
{
$this->watermarkSevice = $watermarkSevice;
}
public static function getSubscribedEvents(): array
{
return [
'crehler.image_booster.generate_media' => ['generateMediaBooster']
];
}
public function generateMediaBooster(EntityWrittenEvent $event)
{
foreach ($event->getWriteResults() as $result) {
if (isset($result->getPayload()['mediaId'])) {
$this->watermarkSevice->appendWatermark($result->getPayload()['mediaId']);
}
}
}
}