<?php
namespace Wbfk\Offer\Event\Flow;
use Shopware\Core\Framework\Event\BusinessEventCollector;
use Shopware\Core\Framework\Event\BusinessEventCollectorEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class BusinessEventCollectorSubscriber implements EventSubscriberInterface
{
private BusinessEventCollector $businessEventCollector;
public function __construct(BusinessEventCollector $businessEventCollector)
{
$this->businessEventCollector = $businessEventCollector;
}
public static function getSubscribedEvents(): array
{
return [
BusinessEventCollectorEvent::NAME => ['onOfferEvent', 1000],
];
}
public function onOfferEvent(BusinessEventCollectorEvent $event): void
{
$this->addDefinition($event, OfferEventApproved::class);
$this->addDefinition($event, OfferEventApprovedInternal::class);
$this->addDefinition($event, OfferEventRequested::class);
}
private function addDefinition(BusinessEventCollectorEvent $event, string $eventName): void
{
$collection = $event->getCollection();
$definition = $this->businessEventCollector->define($eventName);
if (!$definition) {
return;
}
$collection->set($definition->getName(), $definition);
}
}