Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
debug | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
56 | |
0.00% |
0 / 1 |
enable | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
56 |
1 | <?php |
2 | /** |
3 | * |
4 | * This file is part of the phpBB Forum Software package. |
5 | * |
6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
7 | * @license GNU General Public License, version 2 (GPL-2.0) |
8 | * |
9 | * For full copyright and license information, please see |
10 | * the docs/CREDITS.txt file. |
11 | * |
12 | */ |
13 | |
14 | namespace phpbb\debug; |
15 | |
16 | use Symfony\Component\ErrorHandler\BufferingLogger; |
17 | use Symfony\Component\ErrorHandler\DebugClassLoader; |
18 | |
19 | /** |
20 | * Registers all the debug tools. |
21 | |
22 | * @see \Symfony\Component\ErrorHandler\Debug |
23 | */ |
24 | class debug |
25 | { |
26 | private static $enabled = false; |
27 | |
28 | /** |
29 | * Enables the debug tools. |
30 | * |
31 | * This method registers an error handler and an exception handler. |
32 | * |
33 | * If the Symfony ClassLoader component is available, a special |
34 | * class loader is also registered. |
35 | * |
36 | * @param int|null $errorReportingLevel The level of error reporting you want |
37 | * @param bool $displayErrors Whether to display errors (for development) or just log them (for production) |
38 | */ |
39 | public static function enable(int|null $errorReportingLevel = null, bool $displayErrors = true): void |
40 | { |
41 | if (static::$enabled) |
42 | { |
43 | return; |
44 | } |
45 | |
46 | static::$enabled = true; |
47 | |
48 | if ($errorReportingLevel !== null) |
49 | { |
50 | error_reporting($errorReportingLevel); |
51 | } |
52 | else |
53 | { |
54 | error_reporting(-1); |
55 | } |
56 | |
57 | if ('cli' !== php_sapi_name()) |
58 | { |
59 | ini_set('display_errors', 0); |
60 | } |
61 | else if ($displayErrors && (!ini_get('log_errors') || ini_get('error_log'))) |
62 | { |
63 | // CLI - display errors only if they're not already logged to STDERR |
64 | ini_set('display_errors', 1); |
65 | } |
66 | |
67 | DebugClassLoader::enable(); |
68 | |
69 | error_handler::register(new error_handler(new BufferingLogger(), $displayErrors)); |
70 | } |
71 | } |