Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
notify.php
1<?php
2namespace Bitrix\Rest;
3
6
7class Notify
8{
9 const NOTIFY_IM = 'im';
10 const NOTIFY_BOT = 'bot';
11
12 protected $type;
13 protected $userList = array();
14
18 protected $notifier = null;
19
20 public function __construct($notifyType, array $userList)
21 {
22 $this->setType($notifyType);
23 $this->setUserList($userList);
24 }
25
26 public function send($clientId, $token, $method, $message)
27 {
28 foreach($this->userList as $userId)
29 {
30 $this->getNotifier()->send($clientId, $userId, $token, $method, $message);
31 }
32 }
33
34 public function setType($notifyType)
35 {
36 if($notifyType == static::NOTIFY_IM || $notifyType == static::NOTIFY_BOT)
37 {
38 $this->type = $notifyType;
39 }
40 else
41 {
42 throw new ArgumentException('Wrong notify type', 'type');
43 }
44 }
45
46 public function getType()
47 {
48 return $this->type;
49 }
50
51 public function setUserList(array $userList)
52 {
53 if(count($userList) > 0)
54 {
55 $this->userList = $userList;
56 }
57 else
58 {
59 throw new ArgumentNullException('userList');
60 }
61 }
62
63 public function getUserList()
64 {
65 return $this->userList;
66 }
67
71 protected function getNotifier()
72 {
73 if(!$this->notifier)
74 {
75 switch($this->type)
76 {
77 case static::NOTIFY_IM:
78 $this->notifier = new NotifyIm();
79 break;
80 case static::NOTIFY_BOT:
81 $this->notifier = new NotifyIm();
82 break;
83 }
84 }
85
86 return $this->notifier;
87 }
88}
__construct($notifyType, array $userList)
Definition notify.php:20
setUserList(array $userList)
Definition notify.php:51
send($clientId, $token, $method, $message)
Definition notify.php:26
setType($notifyType)
Definition notify.php:34