@@ -169,16 +169,17 @@ public static function enable($mode = NULL, $logDirectory = NULL, $email = NULL)
169169 }
170170 error_reporting (E_ALL );
171171
172- if (! self ::$ enabled ) {
173- register_shutdown_function ([ __CLASS__ , ' shutdownHandler ' ]) ;
174- set_exception_handler ([ __CLASS__ , ' exceptionHandler ' ]);
175- set_error_handler ([ __CLASS__ , ' errorHandler ' ]) ;
172+ if (self ::$ enabled ) {
173+ return ;
174+ }
175+ self :: $ enabled = TRUE ;
176176
177- array_map ('class_exists ' , ['Tracy\Bar ' , 'Tracy\BlueScreen ' , 'Tracy\DefaultBarPanel ' , 'Tracy\Dumper ' ,
178- 'Tracy\FireLogger ' , 'Tracy\Helpers ' , 'Tracy\Logger ' ]);
177+ register_shutdown_function ([__CLASS__ , 'shutdownHandler ' ]);
178+ set_exception_handler ([__CLASS__ , 'exceptionHandler ' ]);
179+ set_error_handler ([__CLASS__ , 'errorHandler ' ]);
179180
180- self :: $ enabled = TRUE ;
181- }
181+ array_map ( ' class_exists ' , [ ' Tracy\Bar ' , ' Tracy\BlueScreen ' , ' Tracy\DefaultBarPanel ' , ' Tracy\Dumper ' ,
182+ ' Tracy\FireLogger ' , ' Tracy\Helpers ' , ' Tracy\Logger ' ]);
182183 }
183184
184185
@@ -209,7 +210,7 @@ public static function shutdownHandler()
209210 FALSE
210211 );
211212
212- } elseif (self ::$ showBar && !connection_aborted () && !self ::$ productionMode && self ::isHtmlMode ()) {
213+ } elseif (self ::$ showBar && !connection_aborted () && !self ::$ productionMode && Helpers ::isHtmlMode ()) {
213214 self ::$ reserved = NULL ;
214215 self ::removeOutputBuffers (FALSE );
215216 self ::getBar ()->render ();
@@ -234,7 +235,7 @@ public static function exceptionHandler($exception, $exit = TRUE)
234235 $ protocol = isset ($ _SERVER ['SERVER_PROTOCOL ' ]) ? $ _SERVER ['SERVER_PROTOCOL ' ] : 'HTTP/1.1 ' ;
235236 $ code = isset ($ _SERVER ['HTTP_USER_AGENT ' ]) && strpos ($ _SERVER ['HTTP_USER_AGENT ' ], 'MSIE ' ) !== FALSE ? 503 : 500 ;
236237 header ("$ protocol $ code " , TRUE , $ code );
237- if (self ::isHtmlMode ()) {
238+ if (Helpers ::isHtmlMode ()) {
238239 header ('Content-Type: text/html; charset=UTF-8 ' );
239240 }
240241 }
@@ -249,15 +250,15 @@ public static function exceptionHandler($exception, $exit = TRUE)
249250 } catch (\Exception $ e ) {
250251 }
251252
252- if (self ::isHtmlMode ()) {
253+ if (Helpers ::isHtmlMode ()) {
253254 $ logged = empty ($ e );
254255 require self ::$ errorTemplate ?: __DIR__ . '/assets/Debugger/error.500.phtml ' ;
255256 } elseif (PHP_SAPI === 'cli ' ) {
256257 fwrite (STDERR , 'ERROR: application encountered an error and can not continue. '
257258 . (isset ($ e ) ? "Unable to log error. \n" : "Error was logged. \n" ));
258259 }
259260
260- } elseif (!connection_aborted () && self ::isHtmlMode ()) {
261+ } elseif (!connection_aborted () && Helpers ::isHtmlMode ()) {
261262 self ::getBlueScreen ()->render ($ exception );
262263 if (self ::$ showBar ) {
263264 self ::getBar ()->render ();
@@ -368,19 +369,11 @@ public static function errorHandler($severity, $message, $file, $line, $context)
368369
369370 } else {
370371 self ::fireLog (new ErrorException ($ message , 0 , $ severity , $ file , $ line ));
371- return self ::isHtmlMode () ? NULL : FALSE ; // FALSE calls normal error handler
372+ return Helpers ::isHtmlMode () ? NULL : FALSE ; // FALSE calls normal error handler
372373 }
373374 }
374375
375376
376- private static function isHtmlMode ()
377- {
378- return empty ($ _SERVER ['HTTP_X_REQUESTED_WITH ' ])
379- && PHP_SAPI !== 'cli '
380- && !preg_match ('#^Content-Type: (?!text/html)#im ' , implode ("\n" , headers_list ()));
381- }
382-
383-
384377 private static function removeOutputBuffers ($ errorOccurred )
385378 {
386379 while (ob_get_level () > self ::$ obLevel ) {
0 commit comments