/** * Handles the event for the object passed as parameter. It calls all subscribed notifiable events that will manage * the event and will call the registered notifiers to send notifications to users. Additionally, persists all * notification in database * * @param string $event Event that was triggered * @param object $object Object that triggered the event * @param \Doctrine\Common\Persistence\ObjectManager $manager Entity manager used to persist built in notification */ public function handleEvent($event, $object, ObjectManager $manager = null) { $notifications = []; foreach ($this->notifiableEventRegistry->getNotifiableEvents() as $notifiable) { if ($notifiable->supportsEvent($event, $object)) { $notifications = array_merge($notifications, $notifiable->getNotifications($event, $object)); } } foreach ($notifications as $notification) { foreach ($this->notifierRegistry->getNotifiers() as $notifier) { $notifier->notify($notification); } if ($manager) { $manager->persist($notification); } } if (count($notifications) > 0 && $manager) { $manager->flush(); } }
private function handleEventConfig($event, $object, NotifiableEventRegistryInterface $notifiableEventRegistry, NotifierRegistryInterface $notifierRegistry, NotifiableEventInterface $notifiableEvent, NotifierInterface $notifier, NotificationInterface $notification) { $notifiableEvent->supportsEvent($event, Argument::any())->shouldBeCalled()->willReturn(true); $notifiableEvent->getNotifications($event, $object)->shouldBeCalled()->willReturn([$notification]); $notifiableEventRegistry->getNotifiableEvents()->willReturn([$notifiableEvent]); $notifier->notify($notification)->shouldBeCalled(); $notifierRegistry->getNotifiers()->shouldBeCalled()->willReturn([$notifier]); }