Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
SendingConfig.php
1<?php
2
4
57{
59 private bool $generateUrlPreview = true;
60
65 private bool $skipUserCheck = false;
66
68 private bool $sendPush = true;
69
71 private bool $sendPushImmediately = false;
72
77 private bool $addRecent = true;
78
80 private bool $skipAuthorAddRecent = false;
81
83 private bool $convertMode = false;
84
86 private bool $skipCommandExecution = false;
87
92 private bool $keepConnectorSilence = false;
93
98 private bool $skipConnectorSend = false;
99
104 private bool $forceConnectorSend = false;
105
110 private bool $skipOpenlineSession = false;
111
112 public function __construct($args = null)
113 {
114 if (is_array($args))
115 {
116 $this->fill($args);
117 }
118 }
119
120 //region Fields magic
121
122 public function __call(string $name, array $arguments)
123 {
124 $fields = $this->fieldMirror();
125 if (isset($fields['flags'][$name]))
126 {
127 return (bool)$this->{$name};
128 }
129
130 foreach ($fields['flags'] as $field => [$key, $switchOn, $switchOff])
131 {
132 if ($name == $switchOn)
133 {
134 $this->{$field} = true;
135 return $this;
136 }
137 if ($name == $switchOff)
138 {
139 $this->{$field} = false;
140 return $this;
141 }
142 }
143
144 return null;
145 }
146
147 public function toArray(): array
148 {
149 $fields = $this->fieldMirror();
150 $data = [];
151 foreach ($fields['flags'] as $field => [$key,,])
152 {
153 $data[$key] = $this->{$field};
154 }
155
156 return $data;
157 }
158
159 public function fill(array $data): void
160 {
161 $fields = $this->fieldMirror();
162 foreach ($data as $field => $value)
163 {
164 if (isset($fields['flags'][$field]))
165 {
166 if (is_bool($value))
167 {
168 $this->{$field} = $value;
169 }
170 else
171 {
172 $this->{$field} = ($value === 'Y');
173 }
174 }
175 }
176 foreach ($fields['flags'] as $field => [$key,,])
177 {
178 if (isset($data[$key]))
179 {
180 if (is_bool($data[$key]))
181 {
182 $this->{$field} = $data[$key];
183 }
184 else
185 {
186 $this->{$field} = ($data[$key] === 'Y');
187 }
188 }
189 }
190 }
191
192 private function fieldMirror(): array
193 {
194 return [
195 'flags' => [
197 'generateUrlPreview' => [
198 'URL_PREVIEW',
199 'enableUrlPreview',
200 'disableUrlPreview',
201 ],
203 'skipUserCheck' => [
204 'SKIP_USER_CHECK',
205 'enableUserCheck',
206 'disableUserCheck',
207 ],
209 'sendPush' => [
210 'PUSH',
211 'allowSendPush',
212 'disallowSendPush',
213 ],
215 'sendPushImmediately' => [
216 'PUSH_IMPORTANT',
217 'allowPushImmediately',
218 'disallowPushImmediately',
219 ],
221 'addRecent' => [
222 'RECENT_ADD',
223 'enableAddRecent',
224 'disableAddRecent',
225 ],
227 'skipAuthorAddRecent' => [
228 'RECENT_SKIP_AUTHOR',
229 'enableSkipAuthorAddRecent',
230 'disableSkipAuthorAddRecent',
231 ],
233 'convertMode' => [
234 'CONVERT',
235 'enableConvertMode',
236 'disableConvertMode',
237 ],
239 'skipCommandExecution' => [
240 'SKIP_COMMAND',
241 'enableSkipCommandExecution',
242 'disableSkipCommandExecution',
243 ],
245 'keepConnectorSilence' => [
246 'SILENT_CONNECTOR',
247 'enableKeepConnectorSilence',
248 'disableKeepConnectorSilence',
249 ],
251 'skipConnectorSend' => [
252 'SKIP_CONNECTOR',
253 'enableSkipConnectorSend',
254 'disableSkipConnectorSend',
255 ],
257 'forceConnectorSend' => [
258 'IMPORTANT_CONNECTOR',
259 'enableForceConnectorSend',
260 'disableForceConnectorSend',
261 ],
263 'skipOpenlineSession' => [
264 'NO_SESSION_OL',
265 'enableSkipOpenlineSession',
266 'disableSkipOpenlineSession',
267 ],
268 ]
269 ];
270 }
271 //endregion
272}
__call(string $name, array $arguments)