mirror of
https://github.com/symfony/debug.git
synced 2026-03-25 09:42:20 +01:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
863d29c31a | ||
|
|
a6f7b78e40 | ||
|
|
9233292b81 |
26
Debug.php
26
Debug.php
@@ -44,8 +44,32 @@ class Debug
|
||||
error_reporting(-1);
|
||||
|
||||
ErrorHandler::register($errorReportingLevel, $displayErrors);
|
||||
if ('cli' !== php_sapi_name()) {
|
||||
if ('cli' !== PHP_SAPI) {
|
||||
ExceptionHandler::register();
|
||||
|
||||
if (PHP_VERSION_ID >= 70000) {
|
||||
$exceptionHandler = set_exception_handler(function ($throwable) use (&$exceptionHandler) {
|
||||
if ($throwable instanceof \Exception) {
|
||||
$exception = $throwable;
|
||||
} else {
|
||||
static $refl = null;
|
||||
|
||||
if (null === $refl) {
|
||||
$refl = array();
|
||||
foreach (array('file', 'line', 'trace') as $prop) {
|
||||
$prop = new \ReflectionProperty('Exception', $prop);
|
||||
$prop->setAccessible(true);
|
||||
$refl[] = $prop;
|
||||
}
|
||||
}
|
||||
$exception = new \Exception($throwable->getMessage(), $throwable->getCode());
|
||||
foreach ($refl as $prop) {
|
||||
$prop->setValue($exception, $throwable->{'get'.$prop->name}());
|
||||
}
|
||||
}
|
||||
$exceptionHandler($exception);
|
||||
});
|
||||
}
|
||||
// CLI - display errors only if they're not already logged to STDERR
|
||||
} elseif ($displayErrors && (!ini_get('log_errors') || ini_get('error_log'))) {
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
@@ -197,6 +197,12 @@ class ErrorHandler
|
||||
$exceptionHandler = set_exception_handler(function () {});
|
||||
restore_exception_handler();
|
||||
|
||||
if (PHP_VERSION_ID >= 70000 && $exceptionHandler instanceof \Closure) {
|
||||
$reflector = new \ReflectionFunction($exceptionHandler);
|
||||
foreach ($reflector->getStaticVariables() as $exceptionHandler) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (is_array($exceptionHandler) && $exceptionHandler[0] instanceof ExceptionHandler) {
|
||||
$level = isset($this->levels[$type]) ? $this->levels[$type] : $type;
|
||||
$message = sprintf('%s: %s in %s line %d', $level, $error['message'], $error['file'], $error['line']);
|
||||
|
||||
43
README.md
43
README.md
@@ -1,44 +1,13 @@
|
||||
Debug Component
|
||||
===============
|
||||
|
||||
Debug provides tools to make debugging easier.
|
||||
|
||||
Enabling all debug tools is as easy as calling the `enable()` method on the
|
||||
main `Debug` class:
|
||||
|
||||
```php
|
||||
use Symfony\Component\Debug\Debug;
|
||||
|
||||
Debug::enable();
|
||||
```
|
||||
|
||||
You can also use the tools individually:
|
||||
|
||||
```php
|
||||
use Symfony\Component\Debug\ErrorHandler;
|
||||
use Symfony\Component\Debug\ExceptionHandler;
|
||||
|
||||
error_reporting(-1);
|
||||
|
||||
ErrorHandler::register($errorReportingLevel);
|
||||
if ('cli' !== php_sapi_name()) {
|
||||
ExceptionHandler::register();
|
||||
} elseif (!ini_get('log_errors') || ini_get('error_log')) {
|
||||
ini_set('display_errors', 1);
|
||||
}
|
||||
```
|
||||
|
||||
Note that the `Debug::enable()` call also registers the debug class loader
|
||||
from the Symfony ClassLoader component when available.
|
||||
|
||||
This component can optionally take advantage of the features of the HttpKernel
|
||||
and HttpFoundation components.
|
||||
The Debug component provides tools to ease debugging PHP code.
|
||||
|
||||
Resources
|
||||
---------
|
||||
|
||||
You can run the unit tests with the following command:
|
||||
|
||||
$ cd path/to/Symfony/Component/Debug/
|
||||
$ composer install
|
||||
$ phpunit
|
||||
* [Documentation](https://symfony.com/doc/current/components/debug/index.html)
|
||||
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
|
||||
* [Report issues](https://github.com/symfony/symfony/issues) and
|
||||
[send Pull Requests](https://github.com/symfony/symfony/pulls)
|
||||
in the [main Symfony repository](https://github.com/symfony/symfony)
|
||||
|
||||
Reference in New Issue
Block a user