/
Configuration.php
171 lines (160 loc) · 7.42 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
<?php
namespace Sentry\SentryBundle\DependencyInjection;
use Raven_Compat;
use Sentry\SentryBundle\EventListener\ExceptionListener;
use Sentry\SentryBundle\EventListener\SentryExceptionListenerInterface;
use Sentry\SentryBundle\SentrySymfonyClient;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
/**
* 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 = new TreeBuilder();
/** @var ArrayNodeDefinition $rootNode */
$rootNode = $treeBuilder->root('sentry');
// Basic Sentry configuration
$rootNode
->children()
->scalarNode('app_path')
->defaultValue('%kernel.root_dir%/..')
->end()
->scalarNode('client')
->defaultValue(SentrySymfonyClient::class)
->end()
->scalarNode('dsn')
->beforeNormalization()
->ifString()
->then($this->getTrimClosure())
->end()
->defaultNull()
->end();
// Sentry client options
$rootNode
->children()
->arrayNode('options')
->addDefaultsIfNotSet()
->children()
->scalarNode('logger')->defaultValue('php')->end()
->scalarNode('server')->defaultNull()->end()
->scalarNode('secret_key')->defaultNull()->end()
->scalarNode('public_key')->defaultNull()->end()
->scalarNode('project')->defaultValue(1)->end()
->booleanNode('auto_log_stacks')->defaultFalse()->end()
->scalarNode('name')->defaultValue(Raven_Compat::gethostname())->end()
->scalarNode('site')->defaultNull()->end()
->arrayNode('tags')
->prototype('scalar')->end()
->end()
->scalarNode('release')->defaultNull()->end()
->scalarNode('environment')->defaultValue('%kernel.environment%')->end()
->scalarNode('sample_rate')->defaultValue(1)->end()
->booleanNode('trace')->defaultTrue()->end()
->scalarNode('timeout')->defaultValue(2)->end()
->scalarNode('message_limit')->defaultValue(\Raven_Client::MESSAGE_LIMIT)->end()
->arrayNode('exclude')
->prototype('scalar')->end()
->end()
->arrayNode('excluded_exceptions')
->prototype('scalar')->end()
->end()
->scalarNode('http_proxy')->defaultNull()->end()
->arrayNode('extra')
->prototype('scalar')->end()
->end()
->scalarNode('curl_method')->defaultValue('sync')->end()
->scalarNode('curl_path')->defaultValue('curl')->end()
->booleanNode('curl_ipv4')->defaultTrue()->end()
->scalarNode('ca_cert')->defaultNull()->end()
->booleanNode('verify_ssl')->defaultTrue()->end()
->scalarNode('curl_ssl_version')->defaultNull()->end()
->scalarNode('trust_x_forwarded_proto')->defaultFalse()->end()
->scalarNode('mb_detect_order')->defaultNull()->end()
->scalarNode('error_types')->defaultNull()->end()
->scalarNode('app_path')->defaultValue('%kernel.root_dir%/..')->end()
->arrayNode('excluded_app_paths')
->defaultValue(
[
'%kernel.root_dir%/../vendor',
'%kernel.root_dir%/../app/cache',
'%kernel.root_dir%/../var/cache',
]
)
->prototype('scalar')->end()
->end()
->arrayNode('prefixes')
->defaultValue(['%kernel.root_dir%/..'])
->prototype('scalar')->end()
->end()
->booleanNode('install_default_breadcrumb_handlers')->defaultTrue()->end()
->booleanNode('install_shutdown_handler')->defaultTrue()->end()
->arrayNode('processors')
->defaultValue([\Raven_Processor_SanitizeDataProcessor::class])
->prototype('scalar')->end()
->end()
->arrayNode('processorOptions')
->arrayPrototype()
->prototype('scalar')->end()
->end()
->end()
->end()
->end();
// Bundle-specific configuration
$rootNode
->children()
->scalarNode('exception_listener')
->defaultValue(ExceptionListener::class)
->validate()
->ifTrue($this->getExceptionListenerInvalidationClosure())
->thenInvalid('The "sentry.exception_listener" parameter should be a FQCN of a class implementing the SentryExceptionListenerInterface interface')
->end()
->end()
->arrayNode('skip_capture')
->prototype('scalar')->end()
->defaultValue([HttpExceptionInterface::class])
->end()
->arrayNode('listener_priorities')
->addDefaultsIfNotSet()
->children()
->scalarNode('request')->defaultValue(0)->end()
->scalarNode('kernel_exception')->defaultValue(0)->end()
->scalarNode('console_exception')->defaultValue(0)->end()
->end()
->end()
->end()
;
return $treeBuilder;
}
private function getExceptionListenerInvalidationClosure(): callable
{
return function ($value) {
$implements = class_implements($value);
if ($implements === false) {
return true;
}
return ! in_array(SentryExceptionListenerInterface::class, $implements, true);
};
}
private function getTrimClosure(): callable
{
return function ($str) {
$value = trim($str);
if ($value === '') {
return null;
}
return $value;
};
}
}