1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
SendingConfig.php
См. документацию.
1<?php
2
3namespace Bitrix\Im\V2\Message\Send;
4
68{
69 protected const TYPE_BOOL = 'BOOL';
70 protected const TYPE_INT = 'INT';
71
72 protected const MAP_LEGACY_TO_ACTUAL_FIELD = [
73 'URL_PREVIEW' => [
74 'actual' => 'generateUrlPreview',
75 'type' => self::TYPE_BOOL,
76 ],
77 'SKIP_USER_CHECK' => [
78 'actual' => 'skipUserCheck',
79 'type' => self::TYPE_BOOL,
80 ],
81 'PUSH' => [
82 'actual' => 'sendPush',
83 'type' => self::TYPE_BOOL,
84 ],
85 'PUSH_IMPORTANT' => [
86 'actual' => 'sendPushImmediately',
87 'type' => self::TYPE_BOOL,
88 ],
89 'RECENT_ADD' => [
90 'actual' => 'addRecent',
91 'type' => self::TYPE_BOOL,
92 ],
93 'RECENT_SKIP_AUTHOR' => [
94 'actual' => 'skipAuthorAddRecent',
95 'type' => self::TYPE_BOOL,
96 ],
97 'CONVERT' => [
98 'actual' => 'convertMode',
99 'type' => self::TYPE_BOOL,
100 ],
101 'SKIP_COMMAND' => [
102 'actual' => 'skipCommandExecution',
103 'type' => self::TYPE_BOOL,
104 ],
105 'SKIP_COUNTER_INCREMENTS' => [
106 'actual' => 'skipCounterIncrements',
107 'type' => self::TYPE_BOOL,
108 ],
109 'SILENT_CONNECTOR' => [
110 'actual' => 'keepConnectorSilence',
111 'type' => self::TYPE_BOOL,
112 ],
113 'SKIP_CONNECTOR' => [
114 'actual' => 'skipConnectorSend',
115 'type' => self::TYPE_BOOL,
116 ],
117 'IMPORTANT_CONNECTOR' => [
118 'actual' => 'forceConnectorSend',
119 'type' => self::TYPE_BOOL,
120 ],
121 'NO_SESSION_OL' => [
122 'actual' => 'skipOpenlineSession',
123 'type' => self::TYPE_BOOL,
124 ],
125 'FAKE_RELATION' => [
126 'actual' => 'fakeRelation',
127 'type' => self::TYPE_INT,
128 ],
129 'SKIP_URL_INDEX' => [
130 'actual' => 'skipUrlIndex',
131 'type' => self::TYPE_BOOL,
132 ],
133 ];
134
136 private bool $generateUrlPreview = true;
137
142 private bool $skipUserCheck = false;
143
145 private bool $sendPush = true;
146
148 private bool $sendPushImmediately = false;
149
154 private bool $addRecent = true;
155
157 private bool $skipAuthorAddRecent = false;
158
160 private bool $convertMode = false;
161
163 private bool $skipCommandExecution = false;
164
165 private bool $skipFireEventBeforeMessageNotifySend = false;
166
167 private bool $skipCounterIncrements = false;
168
173 private bool $keepConnectorSilence = false;
174
179 private bool $skipConnectorSend = false;
180
185 private bool $forceConnectorSend = false;
186
191 private bool $skipOpenlineSession = false;
192
193 private int $fakeRelation = 0;
194
195 public function __construct(?array $args = null)
196 {
197 if (is_array($args))
198 {
199 $this->fillByLegacy($args);
200 }
201 }
202
203 public static function create($sendingConfig): self
204 {
205 if ($sendingConfig instanceof self)
206 {
207 return $sendingConfig;
208 }
209
210 if (is_array($sendingConfig))
211 {
212 return (new static($sendingConfig));
213 }
214
215 return new static();
216 }
217
218 public function fillByLegacy(array $data): void
219 {
220 foreach ($data as $fieldName => $fieldValue)
221 {
222 if (!isset(self::MAP_LEGACY_TO_ACTUAL_FIELD[$fieldName]))
223 {
224 continue;
225 }
226
227 $fieldInfo = self::MAP_LEGACY_TO_ACTUAL_FIELD[$fieldName];
228 $actualFieldName = $fieldInfo['actual'];
229 $this->{$actualFieldName} = $this->prepareValue($fieldInfo['type'], $actualFieldName, $fieldValue);
230 }
231 }
232
234 {
235 return $this->skipFireEventBeforeMessageNotifySend;
236 }
237
238 public function skipFireEventBeforeMessageNotifySend(bool $flag = true): self
239 {
241
242 return $this;
243 }
244
245 //region Fields magic
246
247 public function __call(string $name, array $arguments)
248 {
249 if (isset($this->{$name}))
250 {
251 return $this->{$name};
252 }
253
254 $parseResult = $this->parseFunction($name, $arguments);
255
256 if (empty($parseResult))
257 {
258 return null;
259 }
260
261 [$fieldName, $fieldValue] = $parseResult;
262 $this->{$fieldName} = $fieldValue;
263
264 return $this;
265 }
266
267 protected function parseFunction(string $name, array $arguments): array
268 {
269 $mapPrefixToArgument = [
270 'enable' => true,
271 'allow' => true,
272 'disable' => false,
273 'disallow' => false,
274 'set' => $arguments[0] ?? null,
275 ];
276
277 foreach ($mapPrefixToArgument as $prefix => $argument)
278 {
279 if (str_starts_with($name, $prefix))
280 {
281 return [$this->getFieldNameByFunctionName($name, $prefix), $argument];
282 }
283 }
284
285 return [];
286 }
287
288 protected function getFieldNameByFunctionName(string $name, string $prefix): string
289 {
290 return lcfirst(mb_substr($name, mb_strlen($prefix)));
291 }
292
293 public function toArray(array $options = []): array
294 {
295 $boolAsString = $options['BOOL_AS_STRING'] ?? true;
296
297 $data = [];
298 foreach (self::MAP_LEGACY_TO_ACTUAL_FIELD as $legacyFieldName => $fieldInfo)
299 {
300 $actualFieldName = $fieldInfo['actual'];
301 if ($fieldInfo['type'] === self::TYPE_BOOL && $boolAsString)
302 {
303 $data[$legacyFieldName] = $this->{$actualFieldName} ? 'Y' : 'N';
304 }
305 else
306 {
307 $data[$legacyFieldName] = $this->{$actualFieldName};
308 }
309 }
310
311 return $data;
312 }
313
314 protected function prepareValue(string $type, string $key, $value)
315 {
316 return match ($type)
317 {
318 self::TYPE_BOOL => $this->prepareFlag($value),
319 self::TYPE_INT => (int)$value,
320 default => null,
321 };
322 }
323
324 protected function prepareFlag($value): bool
325 {
326 if (is_bool($value))
327 {
328 return $value;
329 }
330
331 return $value === 'Y';
332 }
333 //endregion
334}
$type
Определения options.php:106
toArray(array $options=[])
Определения SendingConfig.php:293
getFieldNameByFunctionName(string $name, string $prefix)
Определения SendingConfig.php:288
static create($sendingConfig)
Определения SendingConfig.php:203
__call(string $name, array $arguments)
Определения SendingConfig.php:247
parseFunction(string $name, array $arguments)
Определения SendingConfig.php:267
__construct(?array $args=null)
Определения SendingConfig.php:195
prepareValue(string $type, string $key, $value)
Определения SendingConfig.php:314
skipFireEventBeforeMessageNotifySend(bool $flag=true)
Определения SendingConfig.php:238
$options
Определения commerceml2.php:49
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$name
Определения menu_edit.php:35
if(empty($signedUserToken)) $key
Определения quickway.php:257