1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Algatux\InfluxDbBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Algatux\InfluxDbBundle\Events\Listeners\InfluxDbEventListener; |
6
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
7
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* This is the class that validates and merges configuration from your app/config files. |
11
|
|
|
* |
12
|
|
|
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/configuration.html} |
13
|
|
|
*/ |
14
|
|
|
final class Configuration implements ConfigurationInterface |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* {@inheritdoc} |
18
|
|
|
*/ |
19
|
11 |
|
public function getConfigTreeBuilder() |
20
|
|
|
{ |
21
|
11 |
|
if (method_exists(TreeBuilder::class, 'getRootNode')) { |
22
|
|
|
$treeBuilder = new TreeBuilder('influx_db'); |
23
|
|
|
$rootNode = $treeBuilder->getRootNode(); |
24
|
|
|
} else { |
25
|
11 |
|
$treeBuilder = new TreeBuilder(); |
|
|
|
|
26
|
11 |
|
$rootNode = $treeBuilder->root('influx_db'); |
|
|
|
|
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
$rootNode |
30
|
11 |
|
->beforeNormalization() |
31
|
|
|
->ifTrue(function ($v) { |
32
|
11 |
|
return is_array($v) && !array_key_exists('connections', $v); |
33
|
11 |
|
}) |
34
|
|
|
->then(function ($v) { |
35
|
10 |
|
$excludedKeys = ['default_connection']; |
36
|
10 |
|
$connection = []; |
37
|
10 |
|
foreach ($v as $key => $value) { |
38
|
8 |
|
if (in_array($key, $excludedKeys, true)) { |
39
|
2 |
|
continue; |
40
|
|
|
} |
41
|
8 |
|
$connection[$key] = $v[$key]; |
42
|
8 |
|
unset($v[$key]); |
43
|
|
|
} |
44
|
10 |
|
$v['connections'] = ['default' => $connection]; |
45
|
|
|
|
46
|
10 |
|
return $v; |
47
|
11 |
|
}) |
48
|
11 |
|
->end() |
49
|
11 |
|
->children() |
50
|
11 |
|
->scalarNode('default_connection')->info('If not defined, the first connection will be taken.')->end() |
51
|
11 |
|
->arrayNode('connections') |
52
|
11 |
|
->useAttributeAsKey('name') |
53
|
11 |
|
->prototype('array') |
54
|
11 |
|
->children() |
55
|
11 |
|
->scalarNode('host') |
56
|
11 |
|
->isRequired() |
57
|
11 |
|
->info('Your InfluxDB host address') |
58
|
11 |
|
->end() |
59
|
11 |
|
->scalarNode('database') |
60
|
11 |
|
->isRequired() |
61
|
11 |
|
->info('Your InfluxDB database name') |
62
|
11 |
|
->end() |
63
|
11 |
|
->booleanNode('udp') |
64
|
11 |
|
->defaultFalse() |
65
|
11 |
|
->info('Set it to true to activate the UDP connection') |
66
|
11 |
|
->end() |
67
|
11 |
|
->booleanNode('ssl') |
68
|
11 |
|
->defaultFalse() |
69
|
11 |
|
->info('Set it to true to enable SSL on HTTP connections (required for Influx Cloud)') |
70
|
11 |
|
->end() |
71
|
11 |
|
->booleanNode('ssl_verification') |
72
|
11 |
|
->defaultFalse() |
73
|
11 |
|
->info('Set it to true to activate ssl verification') |
74
|
11 |
|
->end() |
75
|
11 |
|
->integerNode('udp_port')->defaultValue(4444)->end() |
76
|
11 |
|
->integerNode('http_port')->defaultValue(8086)->end() |
77
|
11 |
|
->scalarNode('username')->defaultValue('')->end() |
78
|
11 |
|
->scalarNode('password')->defaultValue('')->end() |
79
|
11 |
|
->floatNode('timeout') |
80
|
11 |
|
->defaultValue(0.0) |
81
|
11 |
|
->info('Setup timeout (seconds) for your requests') |
82
|
11 |
|
->end() |
83
|
11 |
|
->floatNode('connect_timeout') |
84
|
11 |
|
->defaultValue(0.0) |
85
|
11 |
|
->info('Setup connection timeout (seconds) for your requests') |
86
|
11 |
|
->end() |
87
|
11 |
|
->booleanNode('listener_enabled') |
88
|
11 |
|
->defaultTrue() |
89
|
11 |
|
->info('Set it to false to disable the event listener configuration') |
90
|
11 |
|
->end() |
91
|
11 |
|
->scalarNode('listener_class') |
92
|
11 |
|
->defaultValue(InfluxDbEventListener::class) |
93
|
11 |
|
->info('Simple override for the default event listener class (constructor args and methods must match)') |
94
|
11 |
|
->end() |
95
|
11 |
|
->end() |
96
|
11 |
|
->end() |
97
|
11 |
|
->end() |
98
|
11 |
|
->end() |
99
|
|
|
; |
100
|
|
|
|
101
|
11 |
|
return $treeBuilder; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
This check looks for function calls that miss required arguments.