<?php
declare(strict_types=1);
namespace NetInventors\NetiNextAdminTools\Subscriber;
use NetInventors\NetiNextAdminTools\Core\FlowTrigger\NetiNextAdminToolsCustomerActivatedEvent;
use NetInventors\NetiNextAdminTools\Core\FlowTrigger\NetiNextAdminToolsCustomerDeactivatedEvent;
use Shopware\Core\Framework\Event\BusinessEventCollector;
use Shopware\Core\Framework\Event\BusinessEventCollectorEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class BusinessEventCollectorSubscriber implements EventSubscriberInterface
{
private BusinessEventCollector $businessEventCollector;
private string $version;
public function __construct(BusinessEventCollector $businessEventCollector, string $version)
{
$this->businessEventCollector = $businessEventCollector;
$this->version = $version;
}
public static function getSubscribedEvents(): array
{
return [
BusinessEventCollectorEvent::NAME => [ 'addEvent', 1000 ],
];
}
public function addEvent(BusinessEventCollectorEvent $event): void
{
if (!\version_compare($this->version, '6.4.6.0', '>=')) {
return;
}
$collection = $event->getCollection();
$flowEvents =
[ NetiNextAdminToolsCustomerActivatedEvent::class, NetiNextAdminToolsCustomerDeactivatedEvent::class ];
foreach ($flowEvents as $flowEvent) {
$definition = $this->businessEventCollector->define($flowEvent);
if (!$definition) {
return;
}
$collection->set($definition->getName(), $definition);
}
}
}