@@ -33,22 +33,25 @@ class DebugHandlersListener implements EventSubscriberInterface
33
33
private $ exceptionHandler ;
34
34
private $ logger ;
35
35
private $ levels ;
36
- private $ debug ;
36
+ private $ throwAt ;
37
+ private $ scream ;
37
38
private $ fileLinkFormat ;
38
39
39
40
/**
40
- * @param callable $exceptionHandler A handler that will be called on Exception
41
+ * @param callable|null $exceptionHandler A handler that will be called on Exception
41
42
* @param LoggerInterface|null $logger A PSR-3 logger
42
43
* @param array|int $levels An array map of E_* to LogLevel::* or an integer bit field of E_* constants
43
- * @param bool $debug Enables/disables debug mode
44
+ * @param int|null $throwAt Thrown errors in a bit field of E_* constants, or null to keep the current value
45
+ * @param bool $scream Enables/disables screaming mode, where even silenced errors are logged
44
46
* @param string $fileLinkFormat The format for links to source files
45
47
*/
46
- public function __construct ($ exceptionHandler , LoggerInterface $ logger = null , $ levels = null , $ debug = true , $ fileLinkFormat = null )
48
+ public function __construct ($ exceptionHandler , LoggerInterface $ logger = null , $ levels = null , $ throwAt = - 1 , $ scream = true , $ fileLinkFormat = null )
47
49
{
48
50
$ this ->exceptionHandler = $ exceptionHandler ;
49
51
$ this ->logger = $ logger ;
50
52
$ this ->levels = $ levels ;
51
- $ this ->debug = $ debug ;
53
+ $ this ->throwAt = is_numeric ($ throwAt ) ? (int ) $ throwAt : (null === $ throwAt ? null : ($ throwAt ? -1 : null ));
54
+ $ this ->scream = (bool ) $ scream ;
52
55
$ this ->fileLinkFormat = $ fileLinkFormat ?: ini_get ('xdebug.file_link_format ' ) ?: get_cfg_var ('xdebug.file_link_format ' );
53
56
}
54
57
@@ -66,25 +69,28 @@ public function configure(Event $event = null, $eventName = null, EventDispatche
66
69
$ eventDispatcher ->removeListener ($ name , array ($ this , 'configure ' ));
67
70
}
68
71
}
69
- if ($ this ->logger ) {
70
- $ handler = set_error_handler ('var_dump ' , 0 );
71
- $ handler = is_array ($ handler ) ? $ handler [0 ] : null ;
72
- restore_error_handler ();
73
- if ($ handler instanceof ErrorHandler) {
74
- if ($ this ->debug ) {
75
- $ handler ->throwAt (-1 );
76
- }
72
+ $ handler = set_error_handler ('var_dump ' , 0 );
73
+ $ handler = is_array ($ handler ) ? $ handler [0 ] : null ;
74
+ restore_error_handler ();
75
+ if ($ handler instanceof ErrorHandler) {
76
+ if ($ this ->logger ) {
77
77
$ handler ->setDefaultLogger ($ this ->logger , $ this ->levels );
78
78
if (is_array ($ this ->levels )) {
79
79
$ scream = 0 ;
80
80
foreach ($ this ->levels as $ type => $ log ) {
81
81
$ scream |= $ type ;
82
82
}
83
- $ this ->levels = $ scream ;
83
+ } else {
84
+ $ scream = null === $ this ->levels ? E_ALL | E_STRICT : $ this ->levels ;
84
85
}
85
- $ handler ->screamAt ($ this ->levels );
86
+ if ($ this ->scream ) {
87
+ $ handler ->screamAt ($ scream );
88
+ }
89
+ $ this ->logger = $ this ->levels = null ;
90
+ }
91
+ if (null !== $ this ->throwAt ) {
92
+ $ handler ->throwAt ($ this ->throwAt , true );
86
93
}
87
- $ this ->logger = $ this ->levels = null ;
88
94
}
89
95
if (!$ this ->exceptionHandler ) {
90
96
if ($ event instanceof KernelEvent) {
@@ -110,7 +116,9 @@ public function configure(Event $event = null, $eventName = null, EventDispatche
110
116
}
111
117
if ($ handler instanceof ExceptionHandler) {
112
118
$ handler ->setHandler ($ this ->exceptionHandler );
113
- $ handler ->setFileLinkFormat ($ this ->fileLinkFormat );
119
+ if (null !== $ this ->fileLinkFormat ) {
120
+ $ handler ->setFileLinkFormat ($ this ->fileLinkFormat );
121
+ }
114
122
}
115
123
$ this ->exceptionHandler = null ;
116
124
}
0 commit comments