custom/plugins/NetiNextAdminTools/src/Subscriber/BusinessEventCollectorSubscriber.php line 32

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace NetInventors\NetiNextAdminTools\Subscriber;
  4. use NetInventors\NetiNextAdminTools\Core\FlowTrigger\NetiNextAdminToolsCustomerActivatedEvent;
  5. use NetInventors\NetiNextAdminTools\Core\FlowTrigger\NetiNextAdminToolsCustomerDeactivatedEvent;
  6. use Shopware\Core\Framework\Event\BusinessEventCollector;
  7. use Shopware\Core\Framework\Event\BusinessEventCollectorEvent;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. class BusinessEventCollectorSubscriber implements EventSubscriberInterface
  10. {
  11.     private BusinessEventCollector $businessEventCollector;
  12.     private string                 $version;
  13.     public function __construct(BusinessEventCollector $businessEventCollectorstring $version)
  14.     {
  15.         $this->businessEventCollector $businessEventCollector;
  16.         $this->version                $version;
  17.     }
  18.     public static function getSubscribedEvents(): array
  19.     {
  20.         return [
  21.             BusinessEventCollectorEvent::NAME => [ 'addEvent'1000 ],
  22.         ];
  23.     }
  24.     public function addEvent(BusinessEventCollectorEvent $event): void
  25.     {
  26.         if (!\version_compare($this->version'6.4.6.0''>=')) {
  27.             return;
  28.         }
  29.         $collection $event->getCollection();
  30.         $flowEvents =
  31.             [ NetiNextAdminToolsCustomerActivatedEvent::class, NetiNextAdminToolsCustomerDeactivatedEvent::class ];
  32.         foreach ($flowEvents as $flowEvent) {
  33.             $definition $this->businessEventCollector->define($flowEvent);
  34.             if (!$definition) {
  35.                 return;
  36.             }
  37.             $collection->set($definition->getName(), $definition);
  38.         }
  39.     }
  40. }