/** * Handle event * * @param NotificationEvent $event * @param EmailNotification[] $matchedNotifications * @return mixed */ public function handle(NotificationEvent $event, $matchedNotifications) { $entity = $event->getEntity(); // convert notification rules to a list of EmailNotificationInterface $notifications = array(); foreach ($matchedNotifications as $notification) { $notifications[] = new EmailNotificationAdapter($entity, $notification, $this->em); } // send notifications $this->processor->process($entity, $notifications); }
/** * Process events with handlers * * @param NotificationEvent $event * @return NotificationEvent */ public function process(NotificationEvent $event) { $entity = $event->getEntity(); // select rules by entity name and event name $notificationRules = $this->getRulesByCriteria(ClassUtils::getClass($entity), $event->getName()); if (!$notificationRules->isEmpty()) { /** @var EventHandlerInterface $handler */ foreach ($this->handlers as $handler) { $handler->handle($event, $notificationRules); if ($event->isPropagationStopped()) { break; } } } return $event; }
public function testGetEntity() { $this->assertEquals($this->entity, $this->event->getEntity()); $this->event->setEntity(null); $this->assertEquals(null, $this->event->getEntity()); }