1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Teebot\Configuration; |
6
|
|
|
|
7
|
|
|
use Symfony\Component\Config\Definition\{ |
8
|
|
|
Builder\TreeBuilder, |
9
|
|
|
ConfigurationInterface |
10
|
|
|
}; |
11
|
|
|
|
12
|
|
|
class Config implements ConfigurationInterface |
13
|
|
|
{ |
14
|
|
|
public const DEFAULT_LIMIT = 1; |
15
|
|
|
|
16
|
|
|
public const DEFAULT_OFFSET = -1; |
17
|
|
|
|
18
|
|
|
private const DEFAULT_NAME = 'Teebot_test'; |
19
|
|
|
|
20
|
|
|
private const DEFAULT_URL = 'https://api.telegram.org'; |
21
|
|
|
|
22
|
|
|
private const DEFAULT_FILE_URL = 'https://api.telegram.org/file/bot'; |
23
|
|
|
|
24
|
|
|
private const DEFAULT_TIMEOUT = 3; |
25
|
|
|
|
26
|
|
|
private const DEFAULT_METHOD = 'GET'; |
27
|
|
|
|
28
|
|
|
private const BOT_PREFIX = 'bot'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Returns configuration tree builder object |
32
|
|
|
* |
33
|
|
|
* @return TreeBuilder |
34
|
|
|
*/ |
35
|
|
|
public function getConfigTreeBuilder(): TreeBuilder |
36
|
|
|
{ |
37
|
|
|
$treeBuilder = new TreeBuilder(); |
38
|
|
|
$rootNode = $treeBuilder->root('teebot'); |
39
|
|
|
$rootNode |
40
|
|
|
->addDefaultsIfNotSet() |
|
|
|
|
41
|
|
|
->children() |
42
|
|
|
->scalarNode('token') |
43
|
|
|
->isRequired() |
44
|
|
|
->cannotBeEmpty() |
45
|
|
|
->end() |
46
|
|
|
->scalarNode('name') |
47
|
|
|
->defaultValue(self::DEFAULT_NAME) |
48
|
|
|
->end() |
49
|
|
|
->scalarNode('url') |
50
|
|
|
->defaultValue(self::DEFAULT_URL) |
51
|
|
|
->end() |
52
|
|
|
->scalarNode('file_url') |
53
|
|
|
->defaultValue(self::DEFAULT_FILE_URL) |
54
|
|
|
->end() |
55
|
|
|
->scalarNode('method') |
56
|
|
|
->defaultValue(self::DEFAULT_METHOD) |
57
|
|
|
->end() |
58
|
|
|
->scalarNode('bot_prefix') |
59
|
|
|
->defaultValue(self::BOT_PREFIX) |
60
|
|
|
->end() |
61
|
|
|
->scalarNode('timeout') |
62
|
|
|
->defaultValue(self::DEFAULT_TIMEOUT) |
63
|
|
|
->end() |
64
|
|
|
->arrayNode('options') |
65
|
|
|
->useAttributeAsKey('key') |
66
|
|
|
->prototype('scalar')->end() |
67
|
|
|
->end() |
68
|
|
|
->arrayNode('events') |
69
|
|
|
->prototype('array') |
70
|
|
|
->children() |
71
|
|
|
->scalarNode('command')->end() |
72
|
|
|
->scalarNode('type')->end() |
73
|
|
|
->scalarNode('class')->end() |
74
|
|
|
->arrayNode('params') |
75
|
|
|
->prototype('array') |
76
|
|
|
->useAttributeAsKey('key') |
77
|
|
|
->prototype('scalar')->end() |
78
|
|
|
->end() |
79
|
|
|
->end() |
80
|
|
|
->end() |
81
|
|
|
->end() |
82
|
|
|
->end() |
83
|
|
|
->arrayNode('logger') |
84
|
|
|
->children() |
85
|
|
|
->scalarNode('filename') |
86
|
|
|
->end() |
87
|
|
|
->end() |
88
|
|
|
->end() |
89
|
|
|
->end(); |
90
|
|
|
|
91
|
|
|
return $treeBuilder; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|