Skip to content

Commit df3755c

Browse files
authored
Merge pull request #12 from OxCom/develop
Fix support for key => value configurations
2 parents abcec24 + b4f1098 commit df3755c

File tree

17 files changed

+371
-134
lines changed

17 files changed

+371
-134
lines changed

DependencyInjection/Configuration.php

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class Configuration implements ConfigurationInterface
2424
const ENVIRONMENT = 'production';
2525
const TIMEOUT = 3;
2626

27+
const API_ENDPOINT = 'https://api.rollbar.com/api/1/';
28+
2729
const JS_ITEMS_PER_MINUTE = 60;
2830
const JS_MAX_ITEMS = 0;
2931
const JS_UNCAUGHT_LEVEL = "error";
@@ -80,8 +82,8 @@ public function getConfigTreeBuilder()
8082
->defaultValue('%kernel.logs_dir%/rollbar.log')
8183
->end()
8284
->booleanNode('allow_exec')->defaultTrue()->end()
83-
->scalarNode('endpoint')->defaultValue('https://api.rollbar.com/api/1/')->end()
84-
->scalarNode('base_api_url')->defaultValue('https://api.rollbar.com/api/1/')->end()
85+
->scalarNode('endpoint')->defaultValue(static::API_ENDPOINT)->end()
86+
->scalarNode('base_api_url')->defaultValue(static::API_ENDPOINT)->end()
8587
->scalarNode('branch')->defaultValue(static::BRANCH)->end()
8688
->booleanNode('capture_error_stacktraces')->defaultTrue()->end()
8789
->scalarNode('checkIgnore')->defaultNull()->end()
@@ -90,17 +92,35 @@ public function getConfigTreeBuilder()
9092
->scalarNode('environment')->defaultValue(static::ENVIRONMENT)->end()
9193
->arrayNode('custom')
9294
->treatNullLike([])
93-
->prototype('scalar')->end()
95+
->useAttributeAsKey('key')
96+
->prototype('array')
97+
->children()
98+
->scalarNode('key')->end()
99+
->scalarNode('value')->end()
100+
->end()
101+
->end()
94102
->defaultValue([])
95103
->end()
96104
->arrayNode('error_sample_rates')
97105
->treatNullLike([])
98-
->prototype('scalar')->end()
106+
->useAttributeAsKey('key')
107+
->prototype('array')
108+
->children()
109+
->integerNode('key')->end()
110+
->floatNode('value')->end()
111+
->end()
112+
->end()
99113
->defaultValue([])
100114
->end()
101115
->arrayNode('exception_sample_rates')
102116
->treatNullLike([])
103-
->prototype('scalar')->end()
117+
->useAttributeAsKey('key')
118+
->prototype('array')
119+
->children()
120+
->scalarNode('key')->end()
121+
->floatNode('value')->end()
122+
->end()
123+
->end()
104124
->defaultValue([])
105125
->end()
106126
->scalarNode('fluent_host')->defaultValue(static::FLUENT_HOST)->end()
@@ -137,30 +157,30 @@ public function getConfigTreeBuilder()
137157
->end()
138158
->arrayNode('rollbar_js')->children()
139159
->booleanNode('enabled')->defaultTrue()->end()
140-
->scalarNode('accessToken')->defaultValue('')->end()
141-
->booleanNode('captureUncaught')->defaultTrue()->end()
142-
->scalarNode('uncaughtErrorLevel')->defaultValue(static::JS_UNCAUGHT_LEVEL)->end()
143-
->booleanNode('captureUnhandledRejections')->defaultTrue()->end()
160+
->scalarNode('access_token')->defaultValue('')->end()
161+
->booleanNode('capture_uncaught')->defaultTrue()->end()
162+
->scalarNode('uncaught_error_level')->defaultValue(static::JS_UNCAUGHT_LEVEL)->end()
163+
->booleanNode('capture_unhandled_rejections')->defaultTrue()->end()
144164
->arrayNode('payload')
145165
->treatNullLike([])
146166
->prototype('scalar')->end()
147167
->defaultValue(["environment" => static::ENVIRONMENT])
148168
->end()
149-
->arrayNode('ignoredMessages')
169+
->arrayNode('ignored_messages')
150170
->treatNullLike([])
151171
->prototype('scalar')->end()
152172
->defaultValue([])
153173
->end()
154174
->booleanNode('verbose')->defaultFalse()->end()
155175
->booleanNode('async')->defaultTrue()->end()
156-
->arrayNode('autoInstrument')
176+
->arrayNode('auto_instrument')
157177
->treatNullLike([])
158178
->prototype('scalar')->end()
159179
->defaultValue(static::$autoInstrument)
160180
->end()
161-
->scalarNode('itemsPerMinute')->defaultValue(static::JS_ITEMS_PER_MINUTE)->end()
162-
->scalarNode('maxItems')->defaultValue(static::JS_MAX_ITEMS)->end()
163-
->arrayNode('scrubFields')
181+
->scalarNode('items_per_minute')->defaultValue(static::JS_ITEMS_PER_MINUTE)->end()
182+
->scalarNode('max_items')->defaultValue(static::JS_MAX_ITEMS)->end()
183+
->arrayNode('scrub_fields')
164184
->treatNullLike([])
165185
->prototype('scalar')->end()
166186
->defaultValue(static::$scrubFieldsDefault)

Provider/RollbarHandler.php

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,18 @@ public function __construct(ContainerInterface $container, $level = Logger::ERRO
8888
*/
8989
protected function initialize()
9090
{
91+
$container = $this->getContainer();
92+
9193
try {
92-
$config = $this->getContainer()->getParameter(SymfonyRollbarExtension::ALIAS . '.config');
94+
$config = $container->getParameter(SymfonyRollbarExtension::ALIAS . '.config');
9395
} catch (\Exception $e) {
9496
return null;
9597
}
9698

97-
$kernel = $this->container->get('kernel');
99+
$kernel = $container->get('kernel');
98100
$rConfig = $config['rollbar'];
101+
102+
// override specific values
99103
$override = [
100104
'root' => $kernel->getRootDir(),
101105
'framework' => 'Symfony ' . \Symfony\Component\HttpKernel\Kernel::VERSION,
@@ -105,6 +109,7 @@ protected function initialize()
105109
$rConfig[$key] = $value;
106110
}
107111

112+
// inject services
108113
foreach ($this->injectServices as $option => $method) {
109114
if (empty($rConfig[$option])) {
110115
continue;
@@ -113,11 +118,33 @@ protected function initialize()
113118
$rConfig[$option] = $this->injectService($rConfig[$option], $method);
114119
}
115120

121+
$rConfig = $this->mapConfigValues($rConfig);
122+
116123
$this->exclude = empty($config['exclude']) ? [] : $config['exclude'];
117124

118125
return $rConfig;
119126
}
120127

128+
/**
129+
* Map specific fields in configurations fields
130+
*
131+
* @param array $rConfig
132+
* @return array
133+
*/
134+
protected function mapConfigValues($rConfig)
135+
{
136+
$key = 'error_sample_rates';
137+
foreach ($rConfig[$key] as $const => $value) {
138+
$newKey = constant($const);
139+
unset($rConfig[$key][$const]);
140+
141+
$rConfig[$key][$newKey] = $value;
142+
}
143+
$rConfig[$key] = \array_filter($rConfig[$key]);
144+
145+
return $rConfig;
146+
}
147+
121148
/**
122149
* Inject service into configuration
123150
*
@@ -128,10 +155,12 @@ protected function initialize()
128155
*/
129156
protected function injectService($name, $method)
130157
{
131-
if ($this->container->has($name)) {
132-
$service = $this->container->get($name);
158+
$container = $this->getContainer();
159+
160+
if ($container->has($name)) {
161+
$service = $container->get($name);
133162
} elseif (class_exists($name)) {
134-
$service = new $name($this->container);
163+
$service = new $name($container);
135164
}
136165

137166
if (!empty($service) && method_exists($service, $method)) {

Resources/doc/configuration.rst

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,18 @@ Simple configuration of bundle:
2222
code_version: ''
2323
enable_utf8_sanitization': true
2424
environment: 'production'
25-
custom: []
26-
error_sample_rates: []
27-
exception_sample_rates: []
25+
custom:
26+
- {key: hello, value: world}
27+
- {key: key, value: value}
28+
error_sample_rates:
29+
- {key: E_NOTICE, value: 0.1}
30+
- {key: E_USER_ERROR, value: 0.5}
31+
- {key: E_USER_NOTICE, value: 0.1}
32+
exception_sample_rates:
33+
- {key: \Symfony\Component\Security\Core\Exception\AccessDeniedException, value: 0.1}
34+
- {key: \Symfony\Component\HttpKernel\Exception\NotFoundHttpException, value: 0.5}
35+
- {key: \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException, value: 0.5}
36+
- {key: \Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException, value: 1}
2837
fluent_host: '127.0.0.1'
2938
fluent_port: 24224
3039
fluent_tag: 'rollbar'
Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
11
imports:
2-
- { resource: config.yml }
3-
- { resource: parameters.yml }
2+
- { resource: config.yml }
3+
- { resource: parameters.yml }
44

55
symfony_rollbar:
6-
enable: true
7-
exclude:
8-
- \Symfony\Component\Debug\Exception\FatalErrorException
9-
- \SymfonyRollbarBundle\Tests\Fixtures\MyAwesomeException
10-
- \ParseError
11-
- \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface
12-
rollbar:
13-
access_token: 'SOME_ROLLBAR_ACCESS_TOKEN_123456'
14-
environment: '%kernel.environment%'
15-
person_fn: \SymfonyRollbarBundle\Tests\Fixtures\PersonProvider
16-
checkIgnore: \SymfonyRollbarBundle\Tests\Fixtures\CheckIgnoreProvider
6+
enable: true
7+
exclude:
8+
- \Symfony\Component\Debug\Exception\FatalErrorException
9+
- \SymfonyRollbarBundle\Tests\Fixtures\MyAwesomeException
10+
- \ParseError
11+
- \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface
12+
rollbar:
13+
access_token: 'SOME_ROLLBAR_ACCESS_TOKEN_123456'
14+
environment: '%kernel.environment%'
15+
person_fn: \SymfonyRollbarBundle\Tests\Fixtures\PersonProvider
16+
checkIgnore: \SymfonyRollbarBundle\Tests\Fixtures\CheckIgnoreProvider
17+
custom:
18+
- {key: hello, value: world}
19+
- {key: key, value: value}
20+
exception_sample_rates:
21+
- {key: \Symfony\Component\Security\Core\Exception\AccessDeniedException, value: 0.1}
22+
- {key: \Symfony\Component\HttpKernel\Exception\NotFoundHttpException, value: 0.5}
23+
- {key: \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException, value: 0.5}
24+
- {key: \Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException, value: 1}
25+
error_sample_rates:
26+
- {key: E_NOTICE, value: 0.1}
27+
- {key: E_USER_ERROR, value: 0.5}
28+
- {key: E_USER_NOTICE, value: 0.1}
1729

18-
rollbar_js:
19-
accessToken: 'SOME_ROLLBAR_ACCESS_TOKEN_654321'
20-
payload:
21-
environment: '%kernel.environment%'
30+
rollbar_js:
31+
access_token: 'SOME_ROLLBAR_ACCESS_TOKEN_654321'
32+
payload:
33+
environment: '%kernel.environment%'
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
imports:
2-
- { resource: config.yml }
3-
- { resource: parameters.yml }
2+
- { resource: config.yml }
3+
- { resource: parameters.yml }
44

55
symfony_rollbar:
6-
enable: false
7-
exclude:
8-
- \Symfony\Component\Debug\Exception\FatalErrorException
9-
- \SymfonyRollbarBundle\Tests\Fixtures\MyAwesomeException
10-
- \ParseError
11-
rollbar:
12-
access_token: 'SOME_ROLLBAR_ACCESS_TOKEN_123456'
13-
environment: '%kernel.environment%'
6+
enable: false
7+
exclude:
8+
- \Symfony\Component\Debug\Exception\FatalErrorException
9+
- \SymfonyRollbarBundle\Tests\Fixtures\MyAwesomeException
10+
- \ParseError
11+
rollbar:
12+
access_token: 'SOME_ROLLBAR_ACCESS_TOKEN_123456'
13+
environment: '%kernel.environment%'
1414

15-
rollbar_js:
16-
accessToken: 'SOME_ROLLBAR_ACCESS_TOKEN_654321'
17-
payload:
18-
environment: '%kernel.environment%'
15+
rollbar_js:
16+
access_token: 'SOME_ROLLBAR_ACCESS_TOKEN_654321'
17+
payload:
18+
environment: '%kernel.environment%'
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
imports:
2-
- { resource: config.yml }
3-
- { resource: parameters.yml }
2+
- { resource: config.yml }
3+
- { resource: parameters.yml }
44

55
symfony_rollbar:
6-
enable: true
7-
exclude:
8-
- \Symfony\Component\Debug\Exception\FatalErrorException
9-
- \SymfonyRollbarBundle\Tests\Fixtures\MyAwesomeException
10-
- \ParseError
11-
rollbar:
12-
access_token: 'SOME_ROLLBAR_ACCESS_TOKEN_123456'
13-
environment: '%kernel.environment%'
6+
enable: true
7+
exclude:
8+
- \Symfony\Component\Debug\Exception\FatalErrorException
9+
- \SymfonyRollbarBundle\Tests\Fixtures\MyAwesomeException
10+
- \ParseError
11+
rollbar:
12+
access_token: 'SOME_ROLLBAR_ACCESS_TOKEN_123456'
13+
environment: '%kernel.environment%'
1414

15-
rollbar_js:
16-
enabled: false
17-
accessToken: 'SOME_ROLLBAR_ACCESS_TOKEN_654321'
18-
payload:
19-
environment: '%kernel.environment%'
15+
rollbar_js:
16+
enabled: false
17+
access_token: 'SOME_ROLLBAR_ACCESS_TOKEN_654321'
18+
payload:
19+
environment: '%kernel.environment%'
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
imports:
2-
- { resource: config.yml }
3-
- { resource: parameters.yml }
2+
- { resource: config.yml }
3+
- { resource: parameters.yml }
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
imports:
2-
- { resource: config.yml }
3-
- { resource: parameters.yml }
2+
- { resource: config.yml }
3+
- { resource: parameters.yml }
44

55
symfony_rollbar:
6-
enable: true
7-
exclude:
8-
- \Symfony\Component\Debug\Exception\FatalErrorException
9-
- \SymfonyRollbarBundle\Tests\Fixtures\MyAwesomeException
10-
- \ParseError
11-
rollbar:
12-
access_token: 'SOME_ROLLBAR_ACCESS_TOKEN_123456'
13-
environment: '%kernel.environment%'
14-
person_fn: "get_awesome_person"
15-
checkIgnore: "should_ignore"
6+
enable: true
7+
exclude:
8+
- \Symfony\Component\Debug\Exception\FatalErrorException
9+
- \SymfonyRollbarBundle\Tests\Fixtures\MyAwesomeException
10+
- \ParseError
11+
rollbar:
12+
access_token: 'SOME_ROLLBAR_ACCESS_TOKEN_123456'
13+
environment: '%kernel.environment%'
14+
person_fn: "get_awesome_person"
15+
checkIgnore: "should_ignore"
1616

17-
rollbar_js:
18-
accessToken: 'SOME_ROLLBAR_ACCESS_TOKEN_654321'
19-
payload:
20-
environment: '%kernel.environment%'
17+
rollbar_js:
18+
access_token: 'SOME_ROLLBAR_ACCESS_TOKEN_654321'
19+
payload:
20+
environment: '%kernel.environment%'

0 commit comments

Comments
 (0)