|  | 
| 2 | 2 | 
 | 
| 3 | 3 | namespace Rollbar\Symfony\RollbarBundle\DependencyInjection; | 
| 4 | 4 | 
 | 
|  | 5 | +use Rollbar\Config; | 
|  | 6 | +use Rollbar\Defaults; | 
| 5 | 7 | use Symfony\Component\Config\Definition\Builder\TreeBuilder; | 
| 6 | 8 | use Symfony\Component\Config\Definition\ConfigurationInterface; | 
| 7 | 9 | 
 | 
| 8 | 10 | /** | 
| 9 | 11 |  * Class Configuration | 
|  | 12 | + * | 
| 10 | 13 |  * @link https://rollbar.com/docs/notifier/rollbar-php/#configuration-reference | 
|  | 14 | + * | 
| 11 | 15 |  * @package Rollbar\Symfony\RollbarBundle\DependencyInjection | 
| 12 | 16 |  */ | 
| 13 | 17 | class Configuration implements ConfigurationInterface | 
| 14 | 18 | { | 
| 15 | 19 |     /** | 
| 16 |  | -     * @inheritdoc | 
|  | 20 | +     * {@inheritdoc} | 
| 17 | 21 |      */ | 
| 18 | 22 |     public function getConfigTreeBuilder() | 
| 19 | 23 |     { | 
| 20 | 24 |         $treeBuilder = new TreeBuilder(); | 
| 21 | 25 |         $rollbarConfigNode = $treeBuilder->root(RollbarExtension::ALIAS); | 
|  | 26 | +        $rollbarConfigNodeChildren = $rollbarConfigNode->children(); | 
| 22 | 27 | 
 | 
| 23 |  | -        // the intendation in this method reflects the structure of the rootNode | 
| 24 |  | -        // for convenience | 
| 25 |  | -             | 
| 26 |  | -        foreach (\Rollbar\Config::listOptions() as $option) { | 
| 27 |  | -            // TODO: this is duplicated code from | 
| 28 |  | -            // https://github.com/rollbar/rollbar-php-wordpress/blob/master/src/Plugin.php#L359-L366 | 
| 29 |  | -            // It needs to get replaced with a native rollbar/rollbar-php method | 
| 30 |  | -            // as pointed out here https://github.com/rollbar/rollbar-php/issues/344 | 
| 31 |  | -            $method = lcfirst(str_replace('_', '', ucwords($option, '_'))); | 
| 32 |  | -                     | 
| 33 |  | -            // Handle the "branch" exception | 
| 34 |  | -            switch ($method) { | 
| 35 |  | -                case "branch": | 
| 36 |  | -                    $method = "gitBranch"; | 
| 37 |  | -                    break; | 
| 38 |  | -                case "includeErrorCodeContext": | 
| 39 |  | -                    $method = 'includeCodeContext'; | 
|  | 28 | +        $configOptions = Config::listOptions(); | 
|  | 29 | +        $rollbarDefaults = Defaults::get(); | 
|  | 30 | + | 
|  | 31 | +        foreach ($configOptions as $option) { | 
|  | 32 | +            switch ($option) { | 
|  | 33 | +                case 'branch': | 
|  | 34 | +                    $method = 'gitBranch'; | 
| 40 | 35 |                     break; | 
| 41 |  | -                case "includeExceptionCodeContext": | 
| 42 |  | -                    $method = 'includeExcCodeContext'; | 
|  | 36 | +                default: | 
|  | 37 | +                    $method = $option; | 
| 43 | 38 |                     break; | 
| 44 | 39 |             } | 
| 45 |  | -                     | 
| 46 |  | -            $default = method_exists(\Rollbar\Defaults::get(), $method) ? | 
| 47 |  | -                \Rollbar\Defaults::get()->$method() : | 
| 48 |  | -                null; | 
| 49 |  | -                     | 
| 50 |  | -            $rollbarConfigNode | 
| 51 |  | -                ->children() | 
| 52 |  | -                ->scalarNode($option) | 
| 53 |  | -                ->defaultValue($default) | 
| 54 |  | -                ->end(); | 
|  | 40 | + | 
|  | 41 | +            try { | 
|  | 42 | +                $default = $rollbarDefaults->fromSnakeCase($method); | 
|  | 43 | +            } catch (\Exception $e) { | 
|  | 44 | +                $default = null; | 
|  | 45 | +            } | 
|  | 46 | + | 
|  | 47 | +            if (is_array($default)) { | 
|  | 48 | +                $rollbarConfigNodeChildren | 
|  | 49 | +                    ->arrayNode($option) | 
|  | 50 | +                        ->scalarPrototype()->end() | 
|  | 51 | +                        ->defaultValue($default) | 
|  | 52 | +                    ->end(); | 
|  | 53 | +            } else { | 
|  | 54 | +                $rollbarConfigNodeChildren | 
|  | 55 | +                    ->scalarNode($option) | 
|  | 56 | +                        ->defaultValue($default) | 
|  | 57 | +                    ->end(); | 
|  | 58 | +            } | 
| 55 | 59 |         } | 
| 56 |  | -         | 
| 57 |  | -        $rollbarConfigNode->end(); | 
| 58 | 60 | 
 | 
| 59 | 61 |         return $treeBuilder; | 
| 60 | 62 |     } | 
|  | 
0 commit comments