-
Notifications
You must be signed in to change notification settings - Fork 169
/
Configuration.php
193 lines (175 loc) · 6.81 KB
/
Configuration.php
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
namespace Sentry\SentryBundle\DependencyInjection;
use PackageVersions\Versions;
use Sentry\Options;
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
{
/**
* {@inheritDoc}
* @throws \InvalidArgumentException
* @throws \RuntimeException
*/
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('sentry');
/** @var ArrayNodeDefinition $rootNode */
$rootNode = \method_exists(TreeBuilder::class, 'getRootNode')
? $treeBuilder->getRootNode()
: $treeBuilder->root('sentry');
// Basic Sentry configuration
$rootNode->children()
->scalarNode('dsn')
->defaultNull()
->beforeNormalization()
->ifString()
->then($this->getTrimClosure());
$rootNode->children()
->booleanNode('register_error_listener')
->defaultTrue();
// Options array (to be passed to Sentry\Options constructor) -- please keep alphabetical order!
$optionsNode = $rootNode->children()
->arrayNode('options')
->addDefaultsIfNotSet();
$defaultValues = new Options();
$optionsChildNodes = $optionsNode->children();
$optionsChildNodes->booleanNode('attach_stacktrace');
$optionsChildNodes->variableNode('before_breadcrumb')
->validate()
->ifTrue($this->isNotAValidCallback())
->thenInvalid('Expecting callable or service reference, got %s');
$optionsChildNodes->variableNode('before_send')
->validate()
->ifTrue($this->isNotAValidCallback())
->thenInvalid('Expecting callable or service reference, got %s');
$optionsChildNodes->booleanNode('capture_silenced_errors');
$optionsChildNodes->arrayNode('class_serializers')
->defaultValue([])
->prototype('scalar');
$optionsChildNodes->integerNode('context_lines')
->min(0)
->max(99);
$optionsChildNodes->booleanNode('default_integrations');
$optionsChildNodes->booleanNode('enable_compression');
$optionsChildNodes->scalarNode('environment')
->defaultValue('%kernel.environment%')
->cannotBeEmpty();
$optionsChildNodes->scalarNode('error_types');
$optionsChildNodes->arrayNode('in_app_include')
->defaultValue([
'%kernel.project_dir%/src',
])
->prototype('scalar');
$optionsChildNodes->arrayNode('in_app_exclude')
->defaultValue([
'%kernel.cache_dir%',
'%kernel.project_dir%/vendor',
])
->prototype('scalar');
$optionsChildNodes->arrayNode('excluded_exceptions')
->defaultValue([])
->prototype('scalar');
$optionsChildNodes->scalarNode('http_proxy');
$optionsChildNodes->arrayNode('integrations')
->prototype('scalar')
->validate()
->ifTrue(static function ($value): bool {
if (! is_string($value) && '' != $value) {
return true;
}
return '@' !== $value[0];
})
->thenInvalid('Expecting service reference, got "%s"');
$optionsChildNodes->scalarNode('logger');
$optionsChildNodes->enumNode('max_request_body_size')
->values([
'none',
'small',
'medium',
'always',
]);
$optionsChildNodes->integerNode('max_breadcrumbs')
->min(1);
$optionsChildNodes->integerNode('max_value_length')
->min(1);
$optionsChildNodes->arrayNode('prefixes')
->defaultValue($defaultValues->getPrefixes())
->prototype('scalar');
$optionsChildNodes->scalarNode('project_root');
$optionsChildNodes->scalarNode('release')
->defaultValue(Versions::getVersion(Versions::ROOT_PACKAGE_NAME))
->info('Release version to be reported to sentry, see https://docs.sentry.io/workflow/releases/?platform=php')
->example('my/application@ff11bb');
$optionsChildNodes->floatNode('sample_rate')
->min(0.0)
->max(1.0);
$optionsChildNodes->integerNode('send_attempts')
->min(1);
$optionsChildNodes->booleanNode('send_default_pii');
$optionsChildNodes->scalarNode('server_name');
$optionsChildNodes->arrayNode('tags')
->normalizeKeys(false)
->prototype('scalar');
// Bundle-specific configuration
$listenerPriorities = $rootNode->children()
->arrayNode('listener_priorities')
->addDefaultsIfNotSet()
->children();
$listenerPriorities->scalarNode('request')
->defaultValue(1);
$listenerPriorities->scalarNode('sub_request')
->defaultValue(1);
$listenerPriorities->scalarNode('console')
->defaultValue(1);
$listenerPriorities->scalarNode('request_error')
->defaultValue(128);
$listenerPriorities->scalarNode('console_error')
->defaultValue(128);
// Monolog handler configuration
$monologConfiguration = $rootNode->children()
->arrayNode('monolog')
->addDefaultsIfNotSet()
->children();
$errorHandler = $monologConfiguration
->arrayNode('error_handler')
->addDefaultsIfNotSet()
->children();
$errorHandler->booleanNode('enabled')
->defaultFalse();
$errorHandler->scalarNode('level')
->defaultValue('DEBUG')
->cannotBeEmpty();
$errorHandler->booleanNode('bubble')
->defaultTrue();
return $treeBuilder;
}
private function getTrimClosure(): \Closure
{
return static function ($str): ?string {
$value = trim($str);
if ($value === '') {
return null;
}
return $value;
};
}
private function isNotAValidCallback(): \Closure
{
return static function ($value): bool {
if (is_callable($value)) {
return false;
}
if (is_string($value) && 0 === strpos($value, '@')) {
return false;
}
return true;
};
}
}