Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
message.php
1<?php
2
4
6
7class Message implements \JsonSerializable
8{
9 public array $userList = [];
10 public array $channelList = [];
11 public ?array $body;
12 public ?string $type;
13 public array $userParams; // map: userId => {user specific params}
14 public array $dictionary; // map: key => value
15 public int $expiry;
16
17 public static function fromEvent(array $arrayFields): Message
18 {
19 $instance = new static();
20 $instance->userList = $arrayFields['users'] ?? [];
21 $instance->channelList = $arrayFields['channels'] ?? [];
22
23 $body = $arrayFields['event'];
24 if (is_array($body['user_params']) && !empty($body['user_params']))
25 {
26 $instance->userParams = $arrayFields['event']['user_params'];
27 }
28 if (is_array($body['dictionary']) && !empty($body['dictionary']))
29 {
30 $instance->dictionary = $arrayFields['event']['dictionary'];
31 }
32 $instance->expiry = is_int($body['expiry']) && $body['expiry'] > 0 ? $body['expiry'] : 86400;
33 // for statistics
34 $messageType = "{$body['module_id']}_{$body['command']}";
35 $messageType = preg_replace("/[^\w]/", "", $messageType);
36 $instance->type = $messageType;
37
38 unset($body['user_params']);
39 unset($body['dictionary']);
40 unset($body['expiry']);
41
42 $instance->body = $body;
43
44 return $instance;
45 }
46
47 public function jsonSerialize(): array
48 {
49 $result = [];
50 if (!empty($this->channelList))
51 {
52 $result['channelList'] = $this->channelList;
53 }
54 if (!empty($this->userList))
55 {
56 $result['userList'] = $this->userList;
57 }
58 if (isset($this->body))
59 {
60 $result['body'] = $this->body;
62 }
63 if (isset($this->userParams))
64 {
65 $result['user_params'] = $this->userParams;
66 }
67 if (isset($this->dictionary))
68 {
69 $result['dictionary'] = $this->dictionary;
70 }
71 if (isset($this->expiry))
72 {
73 $result['expiry'] = $this->expiry;
74 }
75 if (isset($this->type))
76 {
77 $result['type'] = $this->type;
78 }
79
80 return $result;
81 }
82}
static recursiveConvertDateToString(array &$params)
Definition common.php:14
static fromEvent(array $arrayFields)
Definition message.php:17