Skip to content

Commit

Permalink
github-9: remove symfony bundle enable config option since rollbar ha…
Browse files Browse the repository at this point in the history
…s its own enabled option
  • Loading branch information
ArturMoczulski committed Apr 17, 2018
1 parent 3530545 commit 28947e4
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 63 deletions.
21 changes: 8 additions & 13 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,11 @@ class Configuration implements ConfigurationInterface
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root(RollbarExtension::ALIAS);
$treeBuilder = new TreeBuilder();
$rollbarConfigNode = $treeBuilder->root(RollbarExtension::ALIAS);

// the intendation in this method reflects the structure of the rootNode
// for convenience

$rootNode->children()
->scalarNode('enable')->defaultTrue()->end();

$rollbarConfigNode = $rootNode->children()
->arrayNode('config');

foreach (\Rollbar\Config::listOptions() as $option) {
// TODO: this is duplicated code from
Expand All @@ -53,13 +47,14 @@ public function getConfigTreeBuilder()
\Rollbar\Defaults::get()->$method() :
null;

$rollbarConfigNode->children()
->scalarNode($option)->defaultValue($default)->end();
$rollbarConfigNode
->children()
->scalarNode($option)
->defaultValue($default)
->end();
}

$rollbarConfigNode->end();

$rootNode->end();
$rollbarConfigNode->end();

return $treeBuilder;
}
Expand Down
4 changes: 0 additions & 4 deletions DependencyInjection/RollbarExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ public function load(array $configs, ContainerBuilder $container)
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

if (empty($config['enable'])) {
return;
}

// load services and register listeners
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
Expand Down
8 changes: 4 additions & 4 deletions EventListener/ErrorListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ protected function isReportable($code)
$config = $this->getContainer()->getParameter(RollbarExtension::ALIAS . '.config');

return true
&& $config['enable']
&& !(error_reporting() === 0 && $config['config']['report_suppressed'])
&& !(($config['config']['use_error_reporting'] && (error_reporting() & $code) === 0))
&& !($config['config']['included_errno'] != -1 && ($code & $config['config']['included_errno']) != $code);
&& $config['enabled']
&& !(error_reporting() === 0 && $config['report_suppressed'])
&& !(($config['use_error_reporting'] && (error_reporting() & $code) === 0))
&& !($config['included_errno'] != -1 && ($code & $config['included_errno']) != $code);
}
}
24 changes: 12 additions & 12 deletions Factories/RollbarHandlerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,37 @@ public function __construct(ContainerInterface $container)
$this->config = $container->getParameter(RollbarExtension::ALIAS . '.config');

if (isset($_ENV['ROLLBAR_TEST_TOKEN']) && $_ENV['ROLLBAR_TEST_TOKEN']) {
$this->config['config']['access_token'] = $_ENV['ROLLBAR_TEST_TOKEN'];
$this->config['access_token'] = $_ENV['ROLLBAR_TEST_TOKEN'];
}

if (empty($this->config['config']['person'])) {
if (empty($this->config['person'])) {
try {
if ($token = $container->get('security.token_storage')->getToken()) {
$this->config['config']['person'] = $token->getUser();
$this->config['person'] = $token->getUser();
}
} catch (\Exception $exception) {
}
}

if (!empty($this->config['config']['person_fn']) &&
is_callable($this->config['config']['person_fn']) ) {
$this->config['config']['person'] = null;
if (!empty($this->config['person_fn']) &&
is_callable($this->config['person_fn']) ) {
$this->config['person'] = null;
}

if (!empty($this->config['enable'])) {
Rollbar::init($this->config['config'], false, false, false);
}
// if (!empty($this->config['enable'])) {
Rollbar::init($this->config, false, false, false);
// }
}

public function createRollbarHandler()
{
if (!empty($this->config['enable'])) {
// if (!empty($this->config['enable'])) {
return new RollbarMonologHandler(
Rollbar::logger(),
Logger::ERROR
);
}
// }

return null;
// return null;
}
}
22 changes: 8 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ This bundle depends on [symfony/monolog-bundle](https://github.com/symfony/monol
```yaml

rollbar:
enable: true
config:
access_token: YourAccessToken
environment: YourEnvironmentName
access_token: YourAccessToken
environment: YourEnvironmentName

monolog:
handlers:
Expand Down Expand Up @@ -107,11 +105,9 @@ All of them can be configured by nesting them in `rollbar.config` array, i.e.:
```yaml

rollbar:
enable: true
config:
access_token: YourAccessToken
environment: YourEnvironmentName
scrub_fields: [password, password_confirmation, credit_card_number]
access_token: YourAccessToken
environment: YourEnvironmentName
scrub_fields: [password, password_confirmation, credit_card_number]

```
Expand All @@ -128,11 +124,9 @@ You can provide your own logic for retrieving user data with the `person_fn` con
```yaml
rollbar:
enable: true
config:
access_token: YourAccessToken
environment: YourEnvironmentName
person_fn: '\Example\UserData::personFn'
access_token: YourAccessToken
environment: YourEnvironmentName
person_fn: '\Example\UserData::personFn'
```

Expand Down
8 changes: 1 addition & 7 deletions Tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,8 @@ public function testParameters()

$defaults[$option] = $default;
}


$default = [
'enable' => true,
'config' => $defaults
];

$this->assertNotEmpty($config);
$this->assertEquals($default, $config);
$this->assertEquals($defaults, $config);
}
}
22 changes: 15 additions & 7 deletions Tests/DependencyInjection/RollbarExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,23 @@ protected function getContainerExtensions()
* @dataProvider generatorConfigVars
*
* @param string $var
* @param mixed $value
* @param mixed $values
*/
public function testConfigEnabledVars($var, $value)
public function testConfigEnabledVars($var, $expected)
{
$this->load();

$this->assertContainerBuilderHasParameter($var, $value);
$param = $this->container->getParameter($var);

foreach ($expected as $key => $value) {
$this->assertEquals($param[$key], $value);
}
}

public function generatorConfigVars()
{
return [
['rollbar.config', ['enable' => true]],
['rollbar.config', ['enabled' => true]],
];
}

Expand All @@ -54,11 +58,15 @@ public function generatorConfigVars()
* @param string $var
* @param mixed $value
*/
public function testConfigDisabledVars($var, $value)
public function testConfigDisabledVars($var, $expected)
{
$this->load(['enable' => false]);
$this->load(['enabled' => false]);

$this->assertContainerBuilderHasParameter($var, $value);
$param = $this->container->getParameter($var);

foreach ($expected as $key => $value) {
$this->assertEquals($param[$key], $value);
}
}

public function testAlias()
Expand Down
2 changes: 0 additions & 2 deletions Tests/Fixtures/app/config/config_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ imports:
- { resource: parameters.yml }

rollbar:
enable: true
config:
access_token: ~

monolog:
Expand Down

0 comments on commit 28947e4

Please sign in to comment.