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,128 +25,106 @@ 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- ->arrayNode ('integrations ' )
87- ->prototype ('scalar ' )
88- ->validate ()
89- ->ifTrue (function ($ value ): bool {
90- if (! is_string ($ value )) {
91- return true ;
92- }
93-
94- return '@ ' !== substr ($ value , 0 , 1 );
95- })
96- ->thenInvalid ('Expecting service reference, got %s ' )
97- ->end ()
98- ->end ()
99- ->end ()
100- ->scalarNode ('logger ' )
101- ->end ()
102- ->integerNode ('max_breadcrumbs ' )
103- ->min (1 )
104- ->end ()
105- ->integerNode ('max_value_length ' )
106- ->min (1 )
107- ->end ()
108- ->arrayNode ('prefixes ' )
109- ->defaultValue ($ defaultValues ->getPrefixes ())
110- ->prototype ('scalar ' )->end ()
111- ->end ()
112- ->scalarNode ('project_root ' )
113- ->defaultValue ($ this ->getProjectRoot ())
114- ->end ()
115- ->scalarNode ('release ' )
116- ->end ()
117- ->floatNode ('sample_rate ' )
118- ->min (0.0 )
119- ->max (1.0 )
120- ->end ()
121- ->integerNode ('send_attempts ' )
122- ->min (1 )
123- ->end ()
124- ->booleanNode ('send_default_pii ' )->end ()
125- ->scalarNode ('server_name ' )
126- ->end ()
127- ->arrayNode ('tags ' )
128- ->normalizeKeys (false )
129- ->prototype ('scalar ' )
130- ->end ()
131- ;
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 ' );
132111
133112 // Bundle-specific configuration
134- $ rootNode ->children ()
113+ $ listenerPriorities = $ rootNode ->children ()
135114 ->arrayNode ('listener_priorities ' )
136- ->addDefaultsIfNotSet ()
137- ->children ()
138- ->scalarNode ('request ' )-> defaultValue ( 1 )-> end ( )
139- -> scalarNode ( ' console ' )-> defaultValue (1 )-> end ()
140- -> end ( )
141- ->end ( );
115+ ->addDefaultsIfNotSet ()
116+ ->children ();
117+ $ listenerPriorities ->scalarNode ('request ' )
118+ -> defaultValue (1 );
119+ $ listenerPriorities -> scalarNode ( ' console ' )
120+ ->defaultValue ( 1 );
142121
143122 return $ treeBuilder ;
144123 }
145124
146- private function getTrimClosure (): callable
125+ private function getTrimClosure (): \ Closure
147126 {
148- return function ($ str ) {
127+ return function ($ str ): ? string {
149128 $ value = trim ($ str );
150129 if ($ value === '' ) {
151130 return null ;
0 commit comments