diff --git a/src/Symfony/Component/Debug/Debug.php b/src/Symfony/Component/Debug/Debug.php new file mode 100644 index 0000000000..d7edc8d2b2 --- /dev/null +++ b/src/Symfony/Component/Debug/Debug.php @@ -0,0 +1,39 @@ + + * + * 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 + */ +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(); + } + } +} diff --git a/src/Symfony/Component/Debug/README.md b/src/Symfony/Component/Debug/README.md index de4dac70b0..7b0f6af722 100644 --- a/src/Symfony/Component/Debug/README.md +++ b/src/Symfony/Component/Debug/README.md @@ -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 --------- diff --git a/src/Symfony/Component/Debug/composer.json b/src/Symfony/Component/Debug/composer.json index 69c9295884..3c10e8514a 100644 --- a/src/Symfony/Component/Debug/composer.json +++ b/src/Symfony/Component/Debug/composer.json @@ -18,6 +18,9 @@ "require": { "php": ">=5.3.3" }, + "suggest": { + "symfony/class-loader": "2.2.*" + } "autoload": { "psr-0": { "Symfony\\Component\\Debug\\": "" } }, diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index d139c81d4d..17d56823c0 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -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';