-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfiguration.php
More file actions
100 lines (90 loc) · 3.6 KB
/
Configuration.php
File metadata and controls
100 lines (90 loc) · 3.6 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
<?php
declare(strict_types=1);
namespace Perfbase\Symfony\DependencyInjection;
use Perfbase\SDK\FeatureFlags;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('perfbase');
$rootNode = $treeBuilder->getRootNode();
$rootNode
->validate()
->ifTrue(static function (array $config): bool {
return (bool) ($config['enabled'] ?? false) && trim((string) ($config['api_key'] ?? '')) === '';
})
->thenInvalid('The "perfbase.api_key" option must be configured when "perfbase.enabled" is true.')
->end();
$children = $rootNode->children();
$children
->booleanNode('enabled')->defaultFalse()->end()
->booleanNode('debug')->defaultFalse()->end()
->booleanNode('log_errors')->defaultTrue()->end()
->scalarNode('api_key')->defaultValue('')->end()
->scalarNode('api_url')
->cannotBeEmpty()
->defaultValue('https://ingress.perfbase.cloud')
->validate()
->ifTrue(static function ($value): bool {
return !is_string($value) || filter_var($value, FILTER_VALIDATE_URL) === false;
})
->thenInvalid('The "perfbase.api_url" option must be a valid URL.')
->end()
->end()
->floatNode('sample_rate')
->min(0.0)
->max(1.0)
->defaultValue(0.1)
->end()
->integerNode('timeout')
->min(1)
->defaultValue(10)
->end()
->scalarNode('proxy')
->defaultNull()
->validate()
->ifTrue(static function ($value): bool {
return $value !== null
&& (!is_string($value) || $value === '' || filter_var($value, FILTER_VALIDATE_URL) === false);
})
->thenInvalid('The "perfbase.proxy" option must be null or a valid URL.')
->end()
->end()
->integerNode('flags')
->min(0)
->defaultValue(FeatureFlags::DefaultFlags)
->end()
->scalarNode('app_version')->defaultValue('')->end();
$children
->arrayNode('include')
->addDefaultsIfNotSet()
->children()
->arrayNode('http')
->scalarPrototype()->cannotBeEmpty()->end()
->defaultValue(['*'])
->end()
->arrayNode('console')
->scalarPrototype()->cannotBeEmpty()->end()
->defaultValue(['*'])
->end()
->end()
->end();
$children
->arrayNode('exclude')
->addDefaultsIfNotSet()
->children()
->arrayNode('http')
->scalarPrototype()->cannotBeEmpty()->end()
->defaultValue([])
->end()
->arrayNode('console')
->scalarPrototype()->cannotBeEmpty()->end()
->defaultValue([])
->end()
->end()
->end();
return $treeBuilder;
}
}