Passed
Push — develop ( f42afc...651ae1 )
by Michele
04:24
created

Config::getConnectorOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Zanzara;
6
7
use DI\Container;
8
use Psr\Log\LoggerInterface;
9
use React\Cache\CacheInterface;
10
use React\EventLoop\LoopInterface;
11
use React\Socket\Connector;
12
use Zanzara\UpdateMode\Polling;
13
use Zanzara\UpdateMode\ReactPHPWebhook;
14
use Zanzara\UpdateMode\UpdateModeInterface;
15
use Zanzara\UpdateMode\Webhook;
16
17
/**
18
 *
19
 */
20
class Config
21
{
22
23
    public const WEBHOOK_MODE = Webhook::class;
24
    public const POLLING_MODE = Polling::class;
25
    public const REACTPHP_WEBHOOK_MODE = ReactPHPWebhook::class;
26
27
    public const PARSE_MODE_HTML = "HTML";
28
    public const PARSE_MODE_MARKDOWN = "MarkdownV2";
29
    public const PARSE_MODE_MARKDOWN_LEGACY = "Markdown";
30
31
    /**
32
     * @var string
33
     */
34
    private $botToken;
35
36
    /**
37
     * @var LoopInterface|null
38
     */
39
    private $loop;
40
41
    /**
42
     * @var CacheInterface|null
43
     */
44
    private $cache;
45
46
    /**
47
     * @var boolean
48
     */
49
    private $useReactFileSystem = false;
50
51
    /**
52
     * @var Container|null
53
     */
54
    private $container;
55
56
    /**
57
     * @var string|UpdateModeInterface
58
     */
59
    private $updateMode = self::POLLING_MODE;
60
61
    /**
62
     * @var string|null
63
     */
64
    private $parseMode;
65
66
    /**
67
     * @var string
68
     */
69
    private $updateStream = 'php://input';
70
71
    /**
72
     * @var string
73
     */
74
    private $apiTelegramUrl = 'https://api.telegram.org';
75
76
    /**
77
     * @var string
78
     */
79
    private $serverUri = "0.0.0.0:8080";
80
81
    /**
82
     * @var array
83
     */
84
    private $serverContext = [];
85
86
    /**
87
     * @var float
88
     */
89
    private $bulkMessageInterval = 2.0;
90
91
    /**
92
     * @var bool
93
     */
94
    private $webhookTokenCheck = false;
95
96
    /**
97
     * Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling. Should be positive, short polling
98
     * should be used for testing purposes only.
99
     *
100
     * @var int
101
     */
102
    private $pollingTimeout = 50;
103
104
    /**
105
     * Limits the number of updates to be retrieved. Values between 1-100 are accepted. Defaults to 100.
106
     *
107
     * @var int
108
     */
109
    private $pollingLimit = 100;
110
111
    /**
112
     * A JSON-serialized list of the update types you want your bot to receive. For example, specify
113
     * [“message”, “edited_channel_post”, “callback_query”] to only receive updates of these types. See Update for a
114
     * complete list of available update types. Specify an empty list to receive all updates regardless of type
115
     * (default). If not specified, the previous setting will be used. Please note that this parameter doesn't affect
116
     * updates created before the call to the getUpdates, so unwanted updates may be received for a short period of time.
117
     *
118
     * @var array
119
     */
120
    private $pollingAllowedUpdates = [];
121
122
    /**
123
     * @var LoggerInterface|null
124
     */
125
    private $logger;
126
127
    /**
128
     * @var callable|null
129
     */
130
    private $errorHandler;
131
132
    /**
133
     * Default ttl in seconds. Null means that item will stay in the cache
134
     * for as long as the underlying implementation supports.
135
     * Check reactphp cache implementation for more information
136
     * @var float|null
137
     */
138
    private $cacheTtl = 180;
139
140
    /**
141
     * @var Connector|null
142
     */
143
    private $connector;
144
145
    /**
146
     * @var array
147
     */
148
    private $connectorOptions = [];
149
150
    /**
151
     * @var string|null
152
     */
153
    private $proxyUrl;
154
155
    /**
156
     * @var array
157
     */
158
    private $proxyHttpHeaders = [];
159
160
    /**
161
     * @return LoopInterface|null
162
     */
163
    public function getLoop(): ?LoopInterface
164
    {
165
        return $this->loop;
166
    }
167
168
    /**
169
     * @param LoopInterface|null $loop
170
     */
171
    public function setLoop(?LoopInterface $loop): void
172
    {
173
        $this->loop = $loop;
174
    }
175
176
    /**
177
     * @return string|UpdateModeInterface
178
     */
179
    public function getUpdateMode()
180
    {
181
        return $this->updateMode;
182
    }
183
184
    /**
185
     * @param string $updateMode
186
     */
187
    public function setUpdateMode(string $updateMode): void
188
    {
189
        $this->updateMode = $updateMode;
190
    }
191
192
    /**
193
     * @return string|null
194
     */
195
    public function getParseMode(): ?string
196
    {
197
        return $this->parseMode;
198
    }
199
200
    /**
201
     * @param string|null $parseMode
202
     */
203
    public function setParseMode(?string $parseMode): void
204
    {
205
        $this->parseMode = $parseMode;
206
    }
207
208
    /**
209
     * @return string
210
     */
211
    public function getUpdateStream(): string
212
    {
213
        return $this->updateStream;
214
    }
215
216
    /**
217
     * @param string $updateStream
218
     */
219
    public function setUpdateStream(string $updateStream): void
220
    {
221
        $this->updateStream = $updateStream;
222
    }
223
224
    /**
225
     * @return string
226
     */
227
    public function getApiTelegramUrl(): string
228
    {
229
        return $this->apiTelegramUrl;
230
    }
231
232
    /**
233
     * @param string $apiTelegramUrl
234
     */
235
    public function setApiTelegramUrl(string $apiTelegramUrl): void
236
    {
237
        $this->apiTelegramUrl = $apiTelegramUrl;
238
    }
239
240
    /**
241
     * @return string
242
     */
243
    public function getServerUri(): string
244
    {
245
        return $this->serverUri;
246
    }
247
248
    /**
249
     * @param string $serverUri
250
     */
251
    public function setServerUri(string $serverUri): void
252
    {
253
        $this->serverUri = $serverUri;
254
    }
255
256
    /**
257
     * @return array
258
     */
259
    public function getServerContext(): array
260
    {
261
        return $this->serverContext;
262
    }
263
264
    /**
265
     * @param array $serverContext
266
     */
267
    public function setServerContext(array $serverContext): void
268
    {
269
        $this->serverContext = $serverContext;
270
    }
271
272
    /**
273
     * @return float
274
     */
275
    public function getBulkMessageInterval(): float
276
    {
277
        return $this->bulkMessageInterval;
278
    }
279
280
    /**
281
     * @param float $bulkMessageInterval
282
     */
283
    public function setBulkMessageInterval(float $bulkMessageInterval): void
284
    {
285
        $this->bulkMessageInterval = $bulkMessageInterval;
286
    }
287
288
    /**
289
     * @return bool
290
     */
291
    public function isWebhookTokenCheckEnabled(): bool
292
    {
293
        return $this->webhookTokenCheck;
294
    }
295
296
    /**
297
     * @param bool $webhookTokenCheck
298
     */
299
    public function enableWebhookTokenCheck(bool $webhookTokenCheck): void
300
    {
301
        $this->webhookTokenCheck = $webhookTokenCheck;
302
    }
303
304
    /**
305
     * @return int
306
     */
307
    public function getPollingTimeout(): int
308
    {
309
        return $this->pollingTimeout;
310
    }
311
312
    /**
313
     * @param int $pollingTimeout
314
     */
315
    public function setPollingTimeout(int $pollingTimeout): void
316
    {
317
        $this->pollingTimeout = $pollingTimeout;
318
    }
319
320
    /**
321
     * @return int
322
     */
323
    public function getPollingLimit(): int
324
    {
325
        return $this->pollingLimit;
326
    }
327
328
    /**
329
     * @param int $pollingLimit
330
     */
331
    public function setPollingLimit(int $pollingLimit): void
332
    {
333
        $this->pollingLimit = $pollingLimit;
334
    }
335
336
    /**
337
     * @return array
338
     */
339
    public function getPollingAllowedUpdates(): array
340
    {
341
        return $this->pollingAllowedUpdates;
342
    }
343
344
    /**
345
     * @param array $pollingAllowedUpdates
346
     */
347
    public function setPollingAllowedUpdates(array $pollingAllowedUpdates): void
348
    {
349
        $this->pollingAllowedUpdates = $pollingAllowedUpdates;
350
    }
351
352
    /**
353
     * @return LoggerInterface|null
354
     */
355
    public function getLogger(): ?LoggerInterface
356
    {
357
        return $this->logger;
358
    }
359
360
    /**
361
     * @param LoggerInterface|null $logger
362
     */
363
    public function setLogger(?LoggerInterface $logger): void
364
    {
365
        $this->logger = $logger;
366
    }
367
368
    /**
369
     * @return CacheInterface|null
370
     */
371
    public function getCache(): ?CacheInterface
372
    {
373
        return $this->cache;
374
    }
375
376
    /**
377
     * @param CacheInterface|null $cache
378
     */
379
    public function setCache(?CacheInterface $cache): void
380
    {
381
        $this->cache = $cache;
382
    }
383
384
    /**
385
     * @return Container|null
386
     */
387
    public function getContainer(): ?Container
388
    {
389
        return $this->container;
390
    }
391
392
    /**
393
     * @param Container|null $container
394
     */
395
    public function setContainer(?Container $container): void
396
    {
397
        $this->container = $container;
398
    }
399
400
    /**
401
     * @return string
402
     */
403
    public function getBotToken(): string
404
    {
405
        return $this->botToken;
406
    }
407
408
    /**
409
     * @param string $botToken
410
     */
411
    public function setBotToken(string $botToken): void
412
    {
413
        $this->botToken = $botToken;
414
    }
415
416
    /**
417
     * @param bool $bool
418
     */
419
    public function useReactFileSystem(bool $bool)
420
    {
421
        $this->useReactFileSystem = $bool;
422
    }
423
424
    /**
425
     * @return bool
426
     */
427
    public function isReactFileSystem()
428
    {
429
        return $this->useReactFileSystem;
430
    }
431
432
    /**
433
     * @return callable|null
434
     */
435
    public function getErrorHandler(): ?callable
436
    {
437
        return $this->errorHandler;
438
    }
439
440
    /**
441
     * @param callable|null $errorHandler
442
     */
443
    public function setErrorHandler(?callable $errorHandler): void
444
    {
445
        $this->errorHandler = $errorHandler;
446
    }
447
448
    /**
449
     * @return float|null
450
     */
451
    public function getCacheTtl(): ?float
452
    {
453
        return $this->cacheTtl;
454
    }
455
456
    /**
457
     * @param float|null $cacheTtl
458
     */
459
    public function setCacheTtl(?float $cacheTtl): void
460
    {
461
        $this->cacheTtl = $cacheTtl;
462
    }
463
464
    /**
465
     * @return Connector|null
466
     */
467
    public function getConnector(): ?Connector
468
    {
469
        return $this->connector;
470
    }
471
472
    /**
473
     * @param Connector|null $connector
474
     */
475
    public function setConnector(?Connector $connector): void
476
    {
477
        $this->connector = $connector;
478
    }
479
480
    /**
481
     * @return array
482
     */
483
    public function getConnectorOptions(): array
484
    {
485
        return $this->connectorOptions;
486
    }
487
488
    /**
489
     * @param array $connectorOptions
490
     */
491
    public function setConnectorOptions(array $connectorOptions): void
492
    {
493
        $this->connectorOptions = $connectorOptions;
494
    }
495
496
    /**
497
     * @return string|null
498
     */
499
    public function getProxyUrl(): ?string
500
    {
501
        return $this->proxyUrl;
502
    }
503
504
    /**
505
     * @param string|null $proxyUrl
506
     */
507
    public function setProxyUrl(?string $proxyUrl): void
508
    {
509
        $this->proxyUrl = $proxyUrl;
510
    }
511
512
    /**
513
     * @return array
514
     */
515
    public function getProxyHttpHeaders(): array
516
    {
517
        return $this->proxyHttpHeaders;
518
    }
519
520
    /**
521
     * @param array $proxyHttpHeaders
522
     */
523
    public function setProxyHttpHeaders(array $proxyHttpHeaders): void
524
    {
525
        $this->proxyHttpHeaders = $proxyHttpHeaders;
526
    }
527
528
}
529