Skip to content

Commit

Permalink
added a main Debug class to ease integration
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Apr 7, 2013
1 parent 2ff0927 commit 2b305c2
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
39 changes: 39 additions & 0 deletions src/Symfony/Component/Debug/Debug.php
@@ -0,0 +1,39 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Debug;

use Symfony\Component\ClassLoader\DebugClassLoader;

/**
* Registers all the debug tools.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class Debug
{
public static function enable($errorReportingLevel = null)
{
error_reporting(-1);
ini_set('display_errors', 0);

ErrorHandler::register($errorReportingLevel);
if ('cli' !== php_sapi_name()) {
ExceptionHandler::register();
} elseif (!ini_get('log_errors') || ini_get('error_log')) {
ini_set('display_errors', 1);
}

if (class_exists('Symfony\Component\ClassLoader\DebugClassLoader')) {
DebugClassLoader::enable();
}
}
}
15 changes: 11 additions & 4 deletions src/Symfony/Component/Debug/README.md
Expand Up @@ -3,22 +3,29 @@ Debug Component

Debug provides tools to make debugging easier.

Here is classic usage of the main provided tools::
Enabling all debug tools is as easy as calling the `enable()` method on the
main `Debug` class:

use Symfony\Component\Debug\Debug;

Debug::enable();

You can also use the tools individually:

use Symfony\Component\Debug\ErrorHandler;
use Symfony\Component\Debug\ExceptionHandler;

error_reporting(-1);

ErrorHandler::register($this->errorReportingLevel);
ErrorHandler::register($errorReportingLevel);
if ('cli' !== php_sapi_name()) {
ExceptionHandler::register();
} elseif (!ini_get('log_errors') || ini_get('error_log')) {
ini_set('display_errors', 1);
}

// from the ClassLoader component
DebugClassLoader::enable();
Not that the `Debug::enable()` call also registers the debug class loader from
the Symfony ClassLoader component when available.

Resources
---------
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/Debug/composer.json
Expand Up @@ -18,6 +18,9 @@
"require": {
"php": ">=5.3.3"
},
"suggest": {
"symfony/class-loader": "2.2.*"
}
"autoload": {
"psr-0": { "Symfony\\Component\\Debug\\": "" }
},
Expand Down
1 change: 0 additions & 1 deletion src/Symfony/Component/HttpKernel/Kernel.php
Expand Up @@ -57,7 +57,6 @@ abstract class Kernel implements KernelInterface, TerminableInterface
protected $name;
protected $startTime;
protected $classes;
protected $errorReportingLevel;

const VERSION = '2.3.0-DEV';
const VERSION_ID = '20300';
Expand Down

0 comments on commit 2b305c2

Please sign in to comment.