Skip to content

Commit b4f1098

Browse files
committed
update configuration to be more constant
1 parent e76cb0d commit b4f1098

File tree

9 files changed

+94
-28
lines changed

9 files changed

+94
-28
lines changed

DependencyInjection/Configuration.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,30 +157,30 @@ public function getConfigTreeBuilder()
157157
->end()
158158
->arrayNode('rollbar_js')->children()
159159
->booleanNode('enabled')->defaultTrue()->end()
160-
->scalarNode('accessToken')->defaultValue('')->end()
161-
->booleanNode('captureUncaught')->defaultTrue()->end()
162-
->scalarNode('uncaughtErrorLevel')->defaultValue(static::JS_UNCAUGHT_LEVEL)->end()
163-
->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()
164164
->arrayNode('payload')
165165
->treatNullLike([])
166166
->prototype('scalar')->end()
167167
->defaultValue(["environment" => static::ENVIRONMENT])
168168
->end()
169-
->arrayNode('ignoredMessages')
169+
->arrayNode('ignored_messages')
170170
->treatNullLike([])
171171
->prototype('scalar')->end()
172172
->defaultValue([])
173173
->end()
174174
->booleanNode('verbose')->defaultFalse()->end()
175175
->booleanNode('async')->defaultTrue()->end()
176-
->arrayNode('autoInstrument')
176+
->arrayNode('auto_instrument')
177177
->treatNullLike([])
178178
->prototype('scalar')->end()
179179
->defaultValue(static::$autoInstrument)
180180
->end()
181-
->scalarNode('itemsPerMinute')->defaultValue(static::JS_ITEMS_PER_MINUTE)->end()
182-
->scalarNode('maxItems')->defaultValue(static::JS_MAX_ITEMS)->end()
183-
->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')
184184
->treatNullLike([])
185185
->prototype('scalar')->end()
186186
->defaultValue(static::$scrubFieldsDefault)

Tests/Fixtures/app/config/config_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ symfony_rollbar:
2828
- {key: E_USER_NOTICE, value: 0.1}
2929

3030
rollbar_js:
31-
accessToken: 'SOME_ROLLBAR_ACCESS_TOKEN_654321'
31+
access_token: 'SOME_ROLLBAR_ACCESS_TOKEN_654321'
3232
payload:
3333
environment: '%kernel.environment%'

Tests/Fixtures/app/config/config_test_drb.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ symfony_rollbar:
1313
environment: '%kernel.environment%'
1414

1515
rollbar_js:
16-
accessToken: 'SOME_ROLLBAR_ACCESS_TOKEN_654321'
16+
access_token: 'SOME_ROLLBAR_ACCESS_TOKEN_654321'
1717
payload:
1818
environment: '%kernel.environment%'

Tests/Fixtures/app/config/config_test_drbj.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ symfony_rollbar:
1414

1515
rollbar_js:
1616
enabled: false
17-
accessToken: 'SOME_ROLLBAR_ACCESS_TOKEN_654321'
17+
access_token: 'SOME_ROLLBAR_ACCESS_TOKEN_654321'
1818
payload:
1919
environment: '%kernel.environment%'

Tests/Fixtures/app/config/config_test_if.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ symfony_rollbar:
1515
checkIgnore: "should_ignore"
1616

1717
rollbar_js:
18-
accessToken: 'SOME_ROLLBAR_ACCESS_TOKEN_654321'
18+
access_token: 'SOME_ROLLBAR_ACCESS_TOKEN_654321'
1919
payload:
2020
environment: '%kernel.environment%'

Tests/Fixtures/app/config/config_test_is.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ symfony_rollbar:
1616
checkIgnore: "symfony_rollbar.fixture.check_ignore_provider"
1717

1818
rollbar_js:
19-
accessToken: 'SOME_ROLLBAR_ACCESS_TOKEN_654321'
19+
access_token: 'SOME_ROLLBAR_ACCESS_TOKEN_654321'
2020
payload:
2121
environment: '%kernel.environment%'

Tests/SymfonyRollbarBundle/DependencyInjection/ConfigurationTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,19 @@ public function testParameters()
8686
'local_vars_dump' => false,
8787
],
8888
'rollbar_js' => [
89-
'accessToken' => 'SOME_ROLLBAR_ACCESS_TOKEN_654321',
90-
'payload' => ['environment' => static::$kernel->getEnvironment()],
91-
'enabled' => true,
92-
'captureUncaught' => true,
93-
'uncaughtErrorLevel' => Configuration::JS_UNCAUGHT_LEVEL,
94-
'captureUnhandledRejections' => true,
95-
'ignoredMessages' => [],
96-
'verbose' => false,
97-
'async' => true,
98-
'autoInstrument' => Configuration::$autoInstrument,
99-
'itemsPerMinute' => Configuration::JS_ITEMS_PER_MINUTE,
100-
'maxItems' => Configuration::JS_MAX_ITEMS,
101-
'scrubFields' => Configuration::$scrubFieldsDefault,
89+
'access_token' => 'SOME_ROLLBAR_ACCESS_TOKEN_654321',
90+
'payload' => ['environment' => static::$kernel->getEnvironment()],
91+
'enabled' => true,
92+
'capture_uncaught' => true,
93+
'uncaught_error_level' => Configuration::JS_UNCAUGHT_LEVEL,
94+
'capture_unhandled_rejections' => true,
95+
'ignored_messages' => [],
96+
'verbose' => false,
97+
'async' => true,
98+
'auto_instrument' => Configuration::$autoInstrument,
99+
'items_per_minute' => Configuration::JS_ITEMS_PER_MINUTE,
100+
'max_items' => Configuration::JS_MAX_ITEMS,
101+
'scrub_fields' => Configuration::$scrubFieldsDefault,
102102
],
103103
];
104104

Tests/SymfonyRollbarBundle/Twig/RollbarExtensionTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace SymfonyRollbarBundle\Tests\Twig;
44

55
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
6+
use SymfonyRollbarBundle\DependencyInjection\Configuration;
67
use SymfonyRollbarBundle\Twig\RollbarExtension;
78

89
/**
@@ -64,4 +65,34 @@ public function generatorRollbarEnv()
6465
['test_drbj', true],
6566
];
6667
}
68+
69+
public function testConfigMap()
70+
{
71+
static::bootKernel();
72+
73+
$container = static::$kernel->getContainer();
74+
$rollbarTwig = new RollbarExtension($container);
75+
76+
$method = new \ReflectionMethod($rollbarTwig, 'getJsConfig');
77+
$method->setAccessible(true);
78+
79+
$config = $method->invoke($rollbarTwig);
80+
$expected = [
81+
'accessToken' => 'SOME_ROLLBAR_ACCESS_TOKEN_654321',
82+
'payload' => ['environment' => static::$kernel->getEnvironment()],
83+
'enabled' => true,
84+
'captureUncaught' => true,
85+
'uncaughtErrorLevel' => Configuration::JS_UNCAUGHT_LEVEL,
86+
'captureUnhandledRejections' => true,
87+
'ignoredMessages' => [],
88+
'verbose' => false,
89+
'async' => true,
90+
'autoInstrument' => Configuration::$autoInstrument,
91+
'itemsPerMinute' => Configuration::JS_ITEMS_PER_MINUTE,
92+
'maxItems' => Configuration::JS_MAX_ITEMS,
93+
'scrubFields' => Configuration::$scrubFieldsDefault,
94+
];
95+
96+
$this->assertEquals($expected, $config);
97+
}
6798
}

Twig/RollbarExtension.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ public function getFunctions()
5959
*/
6060
public function rollbarJs()
6161
{
62-
$helper = new RollbarJsHelper($this->config['rollbar_js']);
62+
$config = $this->getJsConfig();
63+
$helper = new RollbarJsHelper($config);
6364

6465
$script = "<script>{{config}};\n{{rollbar-snippet}}</script>";
6566
$script = strtr($script, [
@@ -69,4 +70,38 @@ public function rollbarJs()
6970

7071
return $script;
7172
}
73+
74+
/**
75+
* @return mixed
76+
*/
77+
protected function getJsConfig()
78+
{
79+
$config = $this->config['rollbar_js'];
80+
81+
// we have to map a list of fields
82+
$map = [
83+
'access_token' => 'accessToken',
84+
'capture_uncaught' => 'captureUncaught',
85+
'uncaught_error_level' => 'uncaughtErrorLevel',
86+
'capture_unhandled_rejections' => 'captureUnhandledRejections',
87+
'ignored_messages' => 'ignoredMessages',
88+
'auto_instrument' => 'autoInstrument',
89+
'items_per_minute' => 'itemsPerMinute',
90+
'max_items' => 'maxItems',
91+
'scrub_fields' => 'scrubFields',
92+
];
93+
94+
foreach ($map as $old => $new) {
95+
if (!isset($config[$old])) {
96+
continue;
97+
}
98+
99+
$value = $config[$old];
100+
unset($config[$old]);
101+
102+
$config[$new] = $value;
103+
}
104+
105+
return $config;
106+
}
72107
}

0 commit comments

Comments
 (0)