1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of Ekino New Relic bundle. |
7
|
|
|
* |
8
|
|
|
* (c) Ekino - Thomas Rabaix <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Ekino\NewRelicBundle\DependencyInjection; |
15
|
|
|
|
16
|
|
|
use Psr\Log\LogLevel; |
17
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
18
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
19
|
|
|
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
20
|
|
|
use Twig\Environment; |
21
|
|
|
|
22
|
|
|
class Configuration implements ConfigurationInterface |
23
|
|
|
{ |
24
|
|
|
public function getConfigTreeBuilder(): TreeBuilder |
25
|
|
|
{ |
26
|
|
|
$treeBuilder = new TreeBuilder('ekino_new_relic'); |
27
|
|
|
if (\method_exists(TreeBuilder::class, 'getRootNode')) { |
28
|
|
|
$rootNode = $treeBuilder->getRootNode(); |
29
|
|
|
} else { |
30
|
|
|
$rootNode = $treeBuilder->root('ekino_new_relic'); |
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
$rootNode |
34
|
|
|
->fixXmlConfig('deployment_name') |
35
|
|
|
->children() |
36
|
|
|
->booleanNode('enabled')->defaultTrue()->end() |
37
|
|
|
->scalarNode('interactor')->end() |
38
|
|
|
->booleanNode('twig')->defaultValue(\class_exists(Environment::class))->end() |
39
|
|
|
->scalarNode('api_key')->defaultValue(null)->end() |
40
|
|
|
->scalarNode('api_host')->defaultValue(null)->end() |
41
|
|
|
->scalarNode('license_key')->defaultValue(null)->end() |
42
|
|
|
->scalarNode('application_name')->defaultValue(null)->end() |
43
|
|
|
->arrayNode('deployment_names') |
44
|
|
|
->prototype('scalar') |
45
|
|
|
->end() |
46
|
|
|
->beforeNormalization() |
47
|
|
|
->ifTrue(function ($v) { return !\is_array($v); }) |
48
|
|
|
->then(function ($v) { return \array_values(\array_filter(\explode(';', (string) $v))); }) |
49
|
|
|
->end() |
50
|
|
|
->end() |
51
|
|
|
->scalarNode('xmit')->defaultValue(false)->end() |
52
|
|
|
->booleanNode('logging') |
53
|
|
|
->info('Write logs to a PSR3 logger whenever we send data to NewRelic.') |
54
|
|
|
->defaultFalse() |
55
|
|
|
->end() |
56
|
|
|
->arrayNode('exceptions') |
57
|
|
|
->canBeDisabled() |
58
|
|
|
->end() |
59
|
|
|
->arrayNode('commands') |
60
|
|
|
->canBeDisabled() |
61
|
|
|
->children() |
62
|
|
|
->arrayNode('ignored_commands') |
63
|
|
|
->prototype('scalar') |
64
|
|
|
->end() |
65
|
|
|
->beforeNormalization() |
66
|
|
|
->ifTrue(function ($v) { return !\is_array($v); }) |
67
|
|
|
->then(function ($v) { return (array) $v; }) |
68
|
|
|
->end() |
69
|
|
|
->end() |
70
|
|
|
->end() |
71
|
|
|
->end() |
72
|
|
|
->arrayNode('deprecations') |
73
|
|
|
->canBeDisabled() |
74
|
|
|
->end() |
75
|
|
|
->arrayNode('http') |
76
|
|
|
->canBeDisabled() |
77
|
|
|
->children() |
78
|
|
|
->scalarNode('transaction_naming') |
79
|
|
|
->defaultValue('route') |
80
|
|
|
->validate() |
81
|
|
|
->ifNotInArray(['route', 'controller', 'service']) |
82
|
|
|
->thenInvalid('Invalid transaction naming scheme "%s", must be "route", "controller" or "service".') |
83
|
|
|
->end() |
84
|
|
|
->end() |
85
|
|
|
->scalarNode('transaction_naming_service')->defaultNull()->end() |
86
|
|
|
->arrayNode('ignored_routes') |
87
|
|
|
->prototype('scalar') |
88
|
|
|
->end() |
89
|
|
|
->beforeNormalization() |
90
|
|
|
->ifTrue(function ($v) { return !\is_array($v); }) |
91
|
|
|
->then(function ($v) { return (array) $v; }) |
92
|
|
|
->end() |
93
|
|
|
->end() |
94
|
|
|
->arrayNode('ignored_paths') |
95
|
|
|
->prototype('scalar') |
96
|
|
|
->end() |
97
|
|
|
->beforeNormalization() |
98
|
|
|
->ifTrue(function ($v) { return !\is_array($v); }) |
99
|
|
|
->then(function ($v) { return (array) $v; }) |
100
|
|
|
->end() |
101
|
|
|
->end() |
102
|
|
|
->scalarNode('using_symfony_cache')->defaultFalse()->end() |
103
|
|
|
->end() |
104
|
|
|
->end() |
105
|
|
|
->booleanNode('instrument') |
106
|
|
|
->defaultFalse() |
107
|
|
|
->end() |
108
|
|
|
->arrayNode('monolog') |
109
|
|
|
->canBeEnabled() |
110
|
|
|
->children() |
111
|
|
|
->arrayNode('channels') |
112
|
|
|
->fixXmlConfig('channel', 'elements') |
113
|
|
|
->canBeUnset() |
114
|
|
|
->beforeNormalization() |
115
|
|
|
->ifString() |
116
|
|
|
->then(function ($v) { return ['elements' => [$v]]; }) |
117
|
|
|
->end() |
118
|
|
|
->beforeNormalization() |
119
|
|
|
->ifTrue(function ($v) { return \is_array($v) && \is_numeric(\key($v)); }) |
120
|
|
|
->then(function ($v) { return ['elements' => $v]; }) |
121
|
|
|
->end() |
122
|
|
|
->validate() |
123
|
|
|
->ifTrue(function ($v) { return empty($v); }) |
124
|
|
|
->thenUnset() |
125
|
|
|
->end() |
126
|
|
|
->validate() |
127
|
|
|
->always(function ($v) { |
128
|
|
|
$isExclusive = null; |
129
|
|
|
if (isset($v['type'])) { |
130
|
|
|
$isExclusive = 'exclusive' === $v['type']; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
$elements = []; |
134
|
|
|
foreach ($v['elements'] as $element) { |
135
|
|
|
if (0 === \strpos($element, '!')) { |
136
|
|
|
if (false === $isExclusive) { |
137
|
|
|
throw new InvalidConfigurationException('Cannot combine exclusive/inclusive definitions in channels list.'); |
138
|
|
|
} |
139
|
|
|
$elements[] = \substr($element, 1); |
140
|
|
|
$isExclusive = true; |
141
|
|
|
} else { |
142
|
|
|
if (true === $isExclusive) { |
143
|
|
|
throw new InvalidConfigurationException('Cannot combine exclusive/inclusive definitions in channels list'); |
144
|
|
|
} |
145
|
|
|
$elements[] = $element; |
146
|
|
|
$isExclusive = false; |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
if (!\count($elements)) { |
151
|
|
|
return; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
return ['type' => $isExclusive ? 'exclusive' : 'inclusive', 'elements' => $elements]; |
155
|
|
|
}) |
156
|
|
|
->end() |
157
|
|
|
->children() |
158
|
|
|
->scalarNode('type') |
159
|
|
|
->validate() |
160
|
|
|
->ifNotInArray(['inclusive', 'exclusive']) |
161
|
|
|
->thenInvalid('The type of channels has to be inclusive or exclusive') |
162
|
|
|
->end() |
163
|
|
|
->end() |
164
|
|
|
->arrayNode('elements') |
165
|
|
|
->prototype('scalar')->end() |
166
|
|
|
->end() |
167
|
|
|
->end() |
168
|
|
|
->end() |
169
|
|
|
->scalarNode('level')->defaultValue(LogLevel::ERROR)->end() |
170
|
|
|
->scalarNode('service')->defaultValue('ekino.new_relic.monolog_handler')->end() |
171
|
|
|
->end() |
172
|
|
|
->end() |
173
|
|
|
->end() |
174
|
|
|
; |
175
|
|
|
|
176
|
|
|
return $treeBuilder; |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.