コード例 #1
0
 /**
  * Sends the Notification with the given data.
  *
  * @throws NotificationException
  *
  * @param mixed $data
  *
  * @return Notification $this
  */
 protected function doNotify($data)
 {
     $name = $this->getNotificationConfiguration()->getNotificationType()->getName();
     try {
         $notifier = NotifierFactory::createByName($name);
     } catch (InvalidArgumentException $e) {
         throw new NotificationException(sprintf('Could not load Notifier "%s".', $name), 1, $e);
     }
     try {
         $notifier->configure($this->getNotificationConfiguration())->bindAndValidate($data)->notify($this->getDataset());
     } catch (InvalidArgumentException $e) {
         throw new NotificationException(sprintf('Error configuring "%s". Error: "%s"', $notifier, $e->getMessage()), 3, $e);
     } catch (NotificationException $e) {
         throw new NotificationException(sprintf('Could not send Notification "%s" with error "%s".', $notifier, $e->getMessage()), 2, $e);
     }
     return $this;
 }
コード例 #2
0
 /**
  * Installs a new Notifier to the sfNotificationsPlugin
  *
  * @param array $arguments The argument passed to the task.
  * @param array $options The options set for this task.
  *
  * @return void
  */
 protected function execute($arguments = array(), $options = array())
 {
     $databaseManager = new sfDatabaseManager($this->configuration);
     try {
         /* @var $class Notifier */
         $class = get_class(NotifierFactory::createByName($arguments['notifier']));
     } catch (InvalidArgumentException $e) {
         $this->logSection($this->namespace, sprintf('The Notifier implementation of "%s" could not be found.', $arguments['notifier']));
         throw $e;
     }
     try {
         $notificationType = $class::getNotificationType();
         $notificationAttributes = $class::getAttributeCollection();
         if (!$notificationType instanceof NotificationType) {
             throw new InvalidArgumentException('The given object is no instance of class "NotificationType"', 12);
         }
         if (!$notificationAttributes instanceof NotificationTypeAttributeCollection) {
             throw new InvalidArgumentException('The given object is no instance of "NotificationTypeAttributeCollection', 13);
         }
     } catch (InvalidArgumentException $e) {
         $this->logSection($this->namespace, 'The Notifier could not be installed.');
         $this->logSection($this->namespace, $e->getMessage());
         throw $e;
     }
     try {
         foreach ($notificationAttributes as $eachAttribute) {
             $notificationType->addNotificationTypeAttribute($eachAttribute);
         }
         $notificationType->save();
         $this->logSection($this->namespace, sprintf('Notifier "%s" has been installed.', $class));
     } catch (PropelException $e) {
         $this->logSection($this->namespace, 'The Notifier could not be installed.');
         $this->logSection($this->namespace, $e->getMessage());
         throw $e;
     }
 }
コード例 #3
0
 public function testNotifierExists()
 {
     $notifier = NotifierFactory::createByName('SimpleFile');
     $this->assertInstanceOf('SimpleFileNotifier', $notifier);
 }
コード例 #4
0
 public function setChannel($channel)
 {
     $this->notifier = $this->notifierFactory->create($channel);
     return $this;
 }