Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
base.php
1<?php
3
8
9abstract class Base
10{
14
15 protected int $socketTimeout = 10;
16 protected int $streamTimeout = 30;
17
22 public function setSocketTimeout(int $socketTimeout): Base
23 {
24 $this->socketTimeout = $socketTimeout;
25 return $this;
26 }
27
32 public function setStreamTimeout(int $streamTimeout): Base
33 {
34 $this->streamTimeout = $streamTimeout;
35 return $this;
36 }
37
41 public static function isSupported()
42 {
43 return true;
44 }
45
47 public static function className()
48 {
49 return get_called_class();
50 }
51
52 public function isConfigurable()
53 {
54 return false;
55 }
56
57 public function getType()
58 {
59 return MessageType::SMS;
60 }
61
62 abstract public function getId();
63
64 public function getExternalId()
65 {
66 return $this->getType().':'.$this->getId();
67 }
68
72 abstract public function getName();
73
77 abstract public function getShortName();
78
83 abstract public function canUse();
84
85 abstract public function getFromList();
86
91 public function getDefaultFrom()
92 {
93 $fromList = $this->getFromList();
94 $from = isset($fromList[0]) ? $fromList[0]['id'] : null;
95 //Try to find alphanumeric from
96 foreach ($fromList as $item)
97 {
98 if (!preg_match('#^[0-9]+$#', $item['id']))
99 {
100 $from = $item['id'];
101 break;
102 }
103 }
104 return $from;
105 }
106
110 public function getFirstFromList()
111 {
112 $fromList = $this->getFromList();
113 if (!is_array($fromList))
114 {
115 return null;
116 }
117
118 foreach ($fromList as $item)
119 {
120 if (isset($item['id']) && $item['id'])
121 {
122 return $item['id'];
123 }
124 }
125
126 return null;
127 }
128
133 public function isCorrectFrom($from)
134 {
135 $fromList = $this->getFromList();
136 foreach ($fromList as $item)
137 {
138 if ($from === $item['id'])
139 {
140 return true;
141 }
142 }
143 return false;
144 }
145
150 abstract public function sendMessage(array $messageFieldsFields);
151
158 public static function resolveStatus($serviceStatus)
159 {
161 }
162
163 public function getManageUrl()
164 {
165 return $this->isConfigurable() ? '/crm/configs/sms/?sender='.$this->getId() : '';
166 }
167
171 public function prepareMessageBodyForSave(string $text): string
172 {
173 return Emoji::encode($text);
174 }
175
176 protected function prepareMessageBodyForSend(string $text): string
177 {
178 return Emoji::decode($text);
179 }
180}
static encode($text)
Definition emoji.php:17
static decode($text)
Definition emoji.php:24
Providers Initiator $initiator
Definition base.php:12
sendMessage(array $messageFieldsFields)
Providers Informant $informant
Definition base.php:11
setSocketTimeout(int $socketTimeout)
Definition base.php:22
prepareMessageBodyForSave(string $text)
Definition base.php:171
setStreamTimeout(int $streamTimeout)
Definition base.php:32
prepareMessageBodyForSend(string $text)
Definition base.php:176
static resolveStatus($serviceStatus)
Definition base.php:158
Providers Sender $sender
Definition base.php:13