22
33namespace Sentry \SentryBundle \DependencyInjection ;
44
5+ use Jean85 \PrettyVersions ;
56use Sentry \Options ;
67use Symfony \Component \Config \Definition \Builder \ArrayNodeDefinition ;
78use Symfony \Component \Config \Definition \Builder \TreeBuilder ;
@@ -24,113 +25,108 @@ public function getConfigTreeBuilder()
2425 {
2526 $ treeBuilder = new TreeBuilder ('sentry ' );
2627 /** @var ArrayNodeDefinition $rootNode */
27- $ rootNode = \method_exists (TreeBuilder::class, 'getRootNode ' ) ? $ treeBuilder ->getRootNode () : $ treeBuilder ->root ('sentry ' );
28+ $ rootNode = \method_exists (TreeBuilder::class, 'getRootNode ' )
29+ ? $ treeBuilder ->getRootNode ()
30+ : $ treeBuilder ->root ('sentry ' );
2831
2932 // Basic Sentry configuration
3033 $ rootNode ->children ()
3134 ->scalarNode ('dsn ' )
32- ->beforeNormalization ()
33- ->ifString ()
34- ->then ($ this ->getTrimClosure ())
35- ->end ()
36- ->defaultNull ()
37- ->end ();
35+ ->defaultNull ()
36+ ->beforeNormalization ()
37+ ->ifString ()
38+ ->then ($ this ->getTrimClosure ());
3839
3940 // Options array (to be passed to Sentry\Options constructor) -- please keep alphabetical order!
4041 $ optionsNode = $ rootNode ->children ()
4142 ->arrayNode ('options ' )
4243 ->addDefaultsIfNotSet ();
4344
4445 $ defaultValues = new Options ();
45-
46- $ optionsNode
47- ->children ()
48- ->booleanNode ('attach_stacktrace ' )->end ()
49- ->variableNode ('before_breadcrumb ' )
50- ->validate ()
51- ->ifTrue ($ this ->isNotAValidCallback ())
52- ->thenInvalid ('Expecting callable or service reference, got %s ' )
53- ->end ()
54- ->end ()
55- ->variableNode ('before_send ' )
56- ->validate ()
57- ->ifTrue ($ this ->isNotAValidCallback ())
58- ->thenInvalid ('Expecting callable or service reference, got %s ' )
59- ->end ()
60- ->end ()
61- ->booleanNode ('default_integrations ' )->end ()
62- ->integerNode ('context_lines ' )
63- ->min (0 )
64- ->max (99 )
65- ->end ()
66- ->booleanNode ('enable_compression ' )->end ()
67- ->scalarNode ('environment ' )
68- ->defaultValue ('%kernel.environment% ' )
69- ->cannotBeEmpty ()
70- ->end ()
71- ->scalarNode ('error_types ' )
72- ->end ()
73- ->arrayNode ('in_app_exclude ' )
74- ->defaultValue ([
75- '%kernel.cache_dir% ' ,
76- $ this ->getProjectRoot () . '/vendor ' ,
77- ])
78- ->prototype ('scalar ' )->end ()
79- ->end ()
80- ->arrayNode ('excluded_exceptions ' )
81- ->defaultValue ($ defaultValues ->getExcludedExceptions ())
82- ->prototype ('scalar ' )->end ()
83- ->end ()
84- ->scalarNode ('http_proxy ' )
85- ->end ()
86- // TODO -- integrations
87- ->scalarNode ('logger ' )
88- ->end ()
89- ->integerNode ('max_breadcrumbs ' )
90- ->min (1 )
91- ->end ()
92- ->arrayNode ('prefixes ' )
93- ->defaultValue ($ defaultValues ->getPrefixes ())
94- ->prototype ('scalar ' )->end ()
95- ->end ()
96- ->scalarNode ('project_root ' )
97- ->defaultValue ($ this ->getProjectRoot ())
98- ->end ()
99- ->scalarNode ('release ' )
100- ->end ()
101- ->floatNode ('sample_rate ' )
102- ->min (0.0 )
103- ->max (1.0 )
104- ->end ()
105- ->integerNode ('send_attempts ' )
106- ->min (1 )
107- ->end ()
108- ->booleanNode ('send_default_pii ' )->end ()
109- ->scalarNode ('server_name ' )
110- ->end ()
111- ->arrayNode ('tags ' )
112- ->normalizeKeys (false )
113- ->prototype ('scalar ' )
114- ->end ()
115- ;
46+ $ optionsChildNodes = $ optionsNode ->children ();
47+
48+ $ optionsChildNodes ->booleanNode ('attach_stacktrace ' );
49+ $ optionsChildNodes ->variableNode ('before_breadcrumb ' )
50+ ->validate ()
51+ ->ifTrue ($ this ->isNotAValidCallback ())
52+ ->thenInvalid ('Expecting callable or service reference, got %s ' );
53+ $ optionsChildNodes ->variableNode ('before_send ' )
54+ ->validate ()
55+ ->ifTrue ($ this ->isNotAValidCallback ())
56+ ->thenInvalid ('Expecting callable or service reference, got %s ' );
57+ if (PrettyVersions::getVersion ('sentry/sentry ' )->getPrettyVersion () !== '2.0.0 ' ) {
58+ $ optionsChildNodes ->booleanNode ('capture_silenced_errors ' );
59+ }
60+ $ optionsChildNodes ->integerNode ('context_lines ' )
61+ ->min (0 )
62+ ->max (99 );
63+ $ optionsChildNodes ->booleanNode ('default_integrations ' );
64+ $ optionsChildNodes ->booleanNode ('enable_compression ' );
65+ $ optionsChildNodes ->scalarNode ('environment ' )
66+ ->defaultValue ('%kernel.environment% ' )
67+ ->cannotBeEmpty ();
68+ $ optionsChildNodes ->scalarNode ('error_types ' );
69+ $ optionsChildNodes ->arrayNode ('in_app_exclude ' )
70+ ->defaultValue ([
71+ '%kernel.cache_dir% ' ,
72+ $ this ->getProjectRoot () . '/vendor ' ,
73+ ])
74+ ->prototype ('scalar ' );
75+ $ optionsChildNodes ->arrayNode ('excluded_exceptions ' )
76+ ->defaultValue ($ defaultValues ->getExcludedExceptions ())
77+ ->prototype ('scalar ' );
78+ $ optionsChildNodes ->scalarNode ('http_proxy ' );
79+ $ optionsChildNodes ->arrayNode ('integrations ' )
80+ ->prototype ('scalar ' )
81+ ->validate ()
82+ ->ifTrue (function ($ value ): bool {
83+ if (! is_string ($ value )) {
84+ return true ;
85+ }
86+
87+ return '@ ' !== substr ($ value , 0 , 1 );
88+ })
89+ ->thenInvalid ('Expecting service reference, got %s ' );
90+ $ optionsChildNodes ->scalarNode ('logger ' );
91+ $ optionsChildNodes ->integerNode ('max_breadcrumbs ' )
92+ ->min (1 );
93+ $ optionsChildNodes ->integerNode ('max_value_length ' )
94+ ->min (1 );
95+ $ optionsChildNodes ->arrayNode ('prefixes ' )
96+ ->defaultValue ($ defaultValues ->getPrefixes ())
97+ ->prototype ('scalar ' );
98+ $ optionsChildNodes ->scalarNode ('project_root ' )
99+ ->defaultValue ($ this ->getProjectRoot ());
100+ $ optionsChildNodes ->scalarNode ('release ' );
101+ $ optionsChildNodes ->floatNode ('sample_rate ' )
102+ ->min (0.0 )
103+ ->max (1.0 );
104+ $ optionsChildNodes ->integerNode ('send_attempts ' )
105+ ->min (1 );
106+ $ optionsChildNodes ->booleanNode ('send_default_pii ' );
107+ $ optionsChildNodes ->scalarNode ('server_name ' );
108+ $ optionsChildNodes ->arrayNode ('tags ' )
109+ ->normalizeKeys (false )
110+ ->prototype ('scalar ' );
116111
117112 // Bundle-specific configuration
118- $ rootNode ->children ()
113+ $ listenerPriorities = $ rootNode ->children ()
119114 ->arrayNode ('listener_priorities ' )
120- ->addDefaultsIfNotSet ()
121- ->children ()
122- ->scalarNode ('request ' )->defaultValue (1 )->end ()
123- ->scalarNode ('sub_request ' )->defaultValue (1 )->end ()
124- ->scalarNode ('console ' )->defaultValue (1 )->end ()
125- ->end ()
126- ->end ();
115+ ->addDefaultsIfNotSet ()
116+ ->children ();
117+ $ listenerPriorities ->scalarNode ('request ' )
118+ ->defaultValue (1 );
119+ $ listenerPriorities ->scalarNode ('sub_request ' )
120+ ->defaultValue (1 );
121+ $ listenerPriorities ->scalarNode ('console ' )
122+ ->defaultValue (1 );
127123
128124 return $ treeBuilder ;
129125 }
130126
131- private function getTrimClosure (): callable
127+ private function getTrimClosure (): \ Closure
132128 {
133- return function ($ str ) {
129+ return function ($ str ): ? string {
134130 $ value = trim ($ str );
135131 if ($ value === '' ) {
136132 return null ;
0 commit comments