-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathConfiguration.php
More file actions
125 lines (116 loc) · 4.61 KB
/
Copy pathConfiguration.php
File metadata and controls
125 lines (116 loc) · 4.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
declare(strict_types=1);
namespace M6Web\Bundle\StatsdBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
/**
* This is the class that validates and merges configuration from your app/config files
*
* To learn more see
* {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
*/
class Configuration implements ConfigurationInterface
{
/**
* @return TreeBuilder
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('m6_statsd');
/** @var ArrayNodeDefinition $rootNode */
$rootNode = $treeBuilder->getRootNode();
$this->addServersSection($rootNode);
$this->addClientsSection($rootNode);
$this->addDefaultEventSection($rootNode);
return $treeBuilder;
}
/**
* @param ArrayNodeDefinition $rootNode
*/
private function addServersSection($rootNode): void
{
$rootNode
->children()
->arrayNode('servers')
->useAttributeAsKey('alias', false)
->prototype('array')
->children()
->scalarNode('address')
->isRequired()
->validate()
->ifTrue(
function ($v) {
return substr($v, 0, 6) != 'udp://';
}
)
->thenInvalid("address parameter should begin with 'udp://'")
->end()
->end()
->scalarNode('port')->isRequired()->end()
->end()
->end()
->end()
->end();
}
/**
* @param ArrayNodeDefinition $rootNode
*/
private function addClientsSection($rootNode): void
{
$rootNode
->children()
->arrayNode('clients')
->useAttributeAsKey('alias', false)
->prototype('array')
->children()
->arrayNode('servers')
->prototype('scalar')->end()
->end()
->arrayNode('events')
->useAttributeAsKey('eventName')
->prototype('array')
->children()
->scalarNode('increment')->end()
->scalarNode('decrement')->end()
->scalarNode('count')->end()
->scalarNode('gauge')->end()
->scalarNode('set')->end()
->scalarNode('timing')->end()
->arrayNode('custom_timing')
->children()
->scalarNode('node')->end()
->scalarNode('method')->end()
->end()
->end()
->arrayNode('tags')
->prototype('scalar')->end()
->end()
->booleanNode('immediate_send')->defaultFalse()->end()
->end()
->end()
->end()
->scalarNode('message_formatter')->defaultValue('influxdbstatsd')->end()
->integerNode('to_send_limit')->min(1)->end()
->end()
->end()
->end()
->end();
}
/**
* addDefaultEventSection
*
* @param ArrayNodeDefinition $rootNode
*/
private function addDefaultEventSection($rootNode): void
{
$rootNode
->children()
->booleanNode('base_collectors')
->defaultFalse()
->end()
->booleanNode('console_events')
->defaultFalse()
->end();
}
}