/** * Creates the event and runs the notificator. * * @param mixed[] $parameters * @param \AppBundle\Model\User\User[] $users * @param string[] $channels * @param string $language * @param string|null $template * * @throws \LogicException If the dispatcher is not set. */ public function notify(array $parameters, array $users, array $channels = [], string $language = null, string $template = null) { if (!$this->notificator) { throw new \LogicException('Notification service must be set before running `NotificatableTrait::notify`!'); } $event = new NotificationInput(); if (null !== $language) { $event->setLanguage($language); } array_walk($users, [$event, 'addUser']); // can't flip and walk here since parameter values might be objects // and those must not be flipped. foreach ($parameters as $name => $value) { $event->addParameter($name, $value); } $this->notificator->publishNotification(get_class($this), $event, $channels, $template); }
/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage Cannot apply parameter locale since this parameter is reserved! */ public function addInvalidParameter() { $event = new NotificationInput(); $event->addParameter('locale', 'de'); }