|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Nip\Debug; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Debug\BufferingLogger; |
|
6
|
|
|
use Symfony\Component\Debug\Debug as SymfonyDebug; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class Debug |
|
10
|
|
|
* @package Nip\Debug |
|
11
|
|
|
*/ |
|
12
|
|
|
class Debug extends SymfonyDebug |
|
13
|
|
|
{ |
|
14
|
|
|
private static $enabled = false; |
|
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Enables the debug tools. |
|
18
|
|
|
* |
|
19
|
|
|
* This method registers an error handler and an exception handler. |
|
20
|
|
|
* |
|
21
|
|
|
* If the Symfony ClassLoader component is available, a special |
|
22
|
|
|
* class loader is also registered. |
|
23
|
|
|
* |
|
24
|
|
|
* @param int $errorReportingLevel The level of error reporting you want |
|
25
|
|
|
* @param bool $displayErrors Whether to display errors (for development) or just log them (for production) |
|
26
|
|
|
*/ |
|
27
|
|
|
public static function enable($errorReportingLevel = E_ALL, $displayErrors = true) |
|
28
|
|
|
{ |
|
29
|
|
|
if (static::$enabled) { |
|
|
|
|
|
|
30
|
|
|
return; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
static::$enabled = true; |
|
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
if (null !== $errorReportingLevel) { |
|
36
|
|
|
error_reporting($errorReportingLevel); |
|
37
|
|
|
} else { |
|
38
|
|
|
error_reporting(E_ALL); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
if ('cli' !== PHP_SAPI) { |
|
42
|
|
|
ini_set('display_errors', 0); |
|
43
|
|
|
ExceptionHandler::register($displayErrors); |
|
44
|
|
|
} elseif ($displayErrors && (!ini_get('log_errors') || ini_get('error_log'))) { |
|
45
|
|
|
// CLI - display errors only if they're not already logged to STDERR |
|
46
|
|
|
ini_set('display_errors', 1); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
if ($displayErrors) { |
|
50
|
|
|
$handler = ErrorHandler::register(new ErrorHandler(new BufferingLogger())); |
|
|
|
|
|
|
51
|
|
|
} else { |
|
52
|
|
|
$handler = ErrorHandler::register(); |
|
53
|
|
|
$handler->throwAt(0, true); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
app('container')->share(ErrorHandler::class, $handler); |
|
57
|
|
|
// DebugClassLoader::enable(); |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|