Projekt

Obecné

Profil

Stáhnout (1.75 KB) Statistiky
| Větev: | Revize:
1 cb15593b Cajova-Houba
<?php
2
3
/*
4
 * This file is part of the Symfony package.
5
 *
6
 * (c) Fabien Potencier <fabien@symfony.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Symfony\Component\Debug;
13
14
/**
15
 * Registers all the debug tools.
16
 *
17
 * @author Fabien Potencier <fabien@symfony.com>
18
 */
19
class Debug
20
{
21
    private static $enabled = false;
22
23
    /**
24
     * Enables the debug tools.
25
     *
26
     * This method registers an error handler and an exception handler.
27
     *
28
     * If the Symfony ClassLoader component is available, a special
29
     * class loader is also registered.
30
     *
31
     * @param int  $errorReportingLevel The level of error reporting you want
32
     * @param bool $displayErrors       Whether to display errors (for development) or just log them (for production)
33
     */
34
    public static function enable($errorReportingLevel = E_ALL, $displayErrors = true)
35
    {
36
        if (static::$enabled) {
37
            return;
38
        }
39
40
        static::$enabled = true;
41
42
        if (null !== $errorReportingLevel) {
43
            error_reporting($errorReportingLevel);
44
        } else {
45
            error_reporting(E_ALL);
46
        }
47
48
        if ('cli' !== PHP_SAPI) {
49
            ini_set('display_errors', 0);
50
            ExceptionHandler::register();
51
        } elseif ($displayErrors && (!ini_get('log_errors') || ini_get('error_log'))) {
52
            // CLI - display errors only if they're not already logged to STDERR
53
            ini_set('display_errors', 1);
54
        }
55
        if ($displayErrors) {
56
            ErrorHandler::register(new ErrorHandler(new BufferingLogger()));
57
        } else {
58
            ErrorHandler::register()->throwAt(0, true);
59
        }
60
61
        DebugClassLoader::enable();
62
    }
63
}