HEAD ======= >>>>>>> release-0.2.0
1 <?php
2 /**
3 * Copyright 2012 Native5. All Rights Reserved
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * You may not use this file except in compliance with the License.
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 * PHP version 5.3+
14 *
15 * @category Messaging
16 * @package Native5\Services\Messaging
17 * @author Barada Sahu <barry@native5.com>
18 * @copyright 2012 Native5. All Rights Reserved
19 * @license See attached LICENSE for details
20 * @version GIT: $gitid$
21 * @link http://www.docs.native5.com
22 */
23
24 namespace Native5\Services\Messaging;
25
26 /**
27 * NotificationService
28 *
29 * @category NotificationService
30 * @package Native5\Services\Messaging
31 * @author Barada Sahu <barry@native5.com>
32 * @copyright 2012 Native5. All Rights Reserved
33 * @license See attached NOTICE.md for details
34 * @version Release: 1.0
35 * @link http://www.docs.native5.com
36 * Created : 27-11-2012
37 * Last Modified : Fri Dec 21 09:11:53 2012
38 */
39 class NotificationService
40 {
41
42 private static $_instance;
43
44 private $_registry;
45
46
47 /**
48 * Create an instance of Notification Service.
49 *
50 * @static
51 * @access public
52 * @return void
53 */
54 public static function instance()
55 {
56 if (self::$_instance === null) {
57 self::$_instance = new self;
58 }
59
60 return self::$_instance;
61
62 }//end instance()
63
64
65 /**
66 * __construct
67 *
68 * @access private
69 * @return void
70 */
71 private function __construct()
72 {
73 $this->_registry = array();
74 $this->_registry[Notifier::TYPE_EMAIL] = new RemoteMailNotifier();
75 $this->_registry[Notifier::TYPE_VOICE] = new RemoteVoiceNotifier();
76 $this->_registry[Notifier::TYPE_SMS] = new RemoteSMSNotifier();
77
78 }//end __construct()
79
80
81 /**
82 * sendNotification
83 *
84 * @param mixed $channels Channels on which to send message
85 * @param Message $message Message to send
86 *
87 * @access public
88 * @return void
89 */
<<<<<<< HEAD
90 public function sendNotification($channels, Message $message)
=======
90 public function sendNotification($channels, Message $message, $options=array())
>>>>>>> release-0.2.0
91 {
92 $status = array();
93 foreach ($channels as $channel) {
94 $notifier = $this->_getNotifier($channel);
95 if (empty($notifier) === false) {
<<<<<<< HEAD
96 $status[$channel] = $notifier->notify($message);
=======
96 $status[$channel] = $notifier->notify($message, $options);
>>>>>>> release-0.2.0
97 }
98
99 return $status;
100 }
101
102 }//end sendNotification()
103
104
105 /**
106 * sendAdminNotification
107 *
108 * @param mixed $msgText Text message to send.
109 *
110 * @access public
111 * @return void
112 */
113 public function sendAdminNotification($msgText)
114 {
115 $message = new MailMessage();
116 $message->setSubject('Native5 Server : P1 Issue');
117 $message->setBody($msgText);
118 $mReceipents = array();
119 $mReceipents[] = 'barry@native5.com';
120 $message->setRecipients($mReceipents);
121 $this->sendNotification(array(Notifier::TYPE_EMAIL), $message);
122
123 }//end sendAdminNotification()
124
125
126 /**
127 * getNotifier
128 *
129 * @param mixed $channel Channel for which to get notifier for.
130 *
131 * @access private
132 * @return void
133 */
134 private function _getNotifier($channel)
135 {
136 return $this->_registry[$channel];
137
138 }//end _getNotifier()
139
140
141 }//end class
142
143 ?>
144