Inheritance: implements Namshi\Notificator\ManagerInterface
Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function handle(NotificationInterface $notification)
 {
     /** @var ChainedNotificationInterface $notification */
     foreach ($notification->getNotifications() as $notify) {
         $this->manager->trigger($notify);
     }
 }
Exemplo n.º 2
0
 function notify($event)
 {
     $result = $event->getResult();
     $failed = $result->failureCount() or $result->errorCount();
     $manager = new Manager();
     $manager->addHandler(new NotifySendHandler());
     $notification = new NotifySendNotification("Codeception Tests " . ($failed ? "FAILED" : "PASSED"));
     $manager->trigger($notification);
 }
Exemplo n.º 3
0
 function notify($event)
 {
     $result = $event->getResult();
     $failed = $result->failureCount() or $result->errorCount();
     // print_r($this->config);
     if (!isset($this->config['email'])) {
         throw new \Codeception\Exception\Extension(__CLASS__, 'email option is required');
     }
     $email = $this->config['email'];
     $status = $failed ? 'FAILED' : 'PASSED';
     $print = $event->getPrinter()->printResult($result);
     // create the manager and assign the handler to it
     $manager = new Manager();
     $manager->addHandler(new SimpleEmailHandler());
     $notification = new SimpleEmailNotification($email, "Codeception tests {$status}", $print);
     $manager->trigger($notification);
 }
Exemplo n.º 4
0
 /**
  * @param string                       $event
  * @param NotificationMessageInterface $message
  */
 public function sendNotification($event, NotificationMessageInterface $message)
 {
     /** @var EntityRepository $repository */
     $repository = $this->entityManager->getRepository('CSBillUserBundle:User');
     $message->setUsers($repository->findAll());
     $notification = new ChainedNotification();
     $settings = $this->settings->get(sprintf('notification.%s', $event));
     if ($settings['email']) {
         $notification->addNotifications($this->factory->createEmailNotification($message));
     }
     if ($settings['hipchat']) {
         $notification->addNotifications($this->factory->createHipchatNotification($message));
     }
     if ($settings['sms']) {
         foreach ($message->getUsers() as $user) {
             if (null === $user->getMobile()) {
                 continue;
             }
             $notification->addNotifications($this->factory->createSmsNotification($user->getMobile(), $message));
         }
     }
     $this->notification->trigger($notification);
 }
Exemplo n.º 5
0
<?php

require __DIR__ . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "vendor" . DIRECTORY_SEPARATOR . "autoload.php";
// import namespaces
use Namshi\Notificator\Manager;
use Namshi\Notificator\Notification\Handler\SwiftMailer as SwiftMailerHandler;
use Namshi\Notificator\Notification\Email\SwiftMailer\SwiftMailerNotification;
// create transport
$transport = Swift_SmtpTransport::newInstance('EMAIL_PROVIDER_HOST', 'EMAIL_PROVIDER_PORT');
// set the username and password
$transport->setUsername('USERNAME');
$transport->setPassword('PASSWORD');
// create mailer
$mailer = Swift_Mailer::newInstance($transport);
// create message
$message = new Swift_Message();
$message->setTo('*****@*****.**');
$message->setFrom('*****@*****.**');
$message->setSubject('TEST EMAIL');
$message->setBody('Hello!');
$notification = new SwiftMailerNotification('test_template', array('*****@*****.**'), array());
$notification->setMessage($message);
// create the handler
$handler = new SwiftMailerHandler($mailer);
// create a manager
$manager = new Manager();
$manager->addHandler($handler);
// trigger the notification
$manager->trigger($notification);
Exemplo n.º 6
0
<?php

require __DIR__ . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "vendor" . DIRECTORY_SEPARATOR . "autoload.php";
// import namespaces
use Namshi\Notificator\Manager;
use Namshi\Notificator\Notification\Handler\HipChat as HipChatHandler;
use HipChat\HipChat;
use Namshi\Notificator\Notification\HipChat\HipChatNotification;
// create the manager
$manager = new Manager(array(new HipChatHandler(new HipChat('YOUR_API_TOKEN_HERE'))));
// lets have some fun
$messages = array('Yo @all', 'I am coming', 'to announce', 'that this notifications', 'are coming', 'from an ugly bot', 'and come from PHP', 'Can you imagine that now you can send messages to', 'HipChat directly from a script?', 'And you know what?', 'Python SUCKS. BIG TIME.');
// trigger multiple notifications!
foreach ($messages as $message) {
    // create the notification
    $notification = new HipChatNotification($message, 'NotificatorBot', 'Spam', array('hipchat_notify' => true, 'hipchat_color' => HipChat::COLOR_GREEN, 'hipchat_message_format' => HipChat::FORMAT_TEXT));
    //  trigger the notification
    $manager->trigger($notification);
}