mirror of
https://github.com/symfony/debug.git
synced 2026-03-25 09:42:20 +01:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
863d29c31a | ||
|
|
a6f7b78e40 | ||
|
|
9233292b81 | ||
|
|
7cca5bb1b1 | ||
|
|
d0ee40c1e2 |
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']);
|
||||
|
||||
@@ -141,7 +141,7 @@ class ExceptionHandler
|
||||
$ind = $count - $position + 1;
|
||||
$class = $this->abbrClass($e['class']);
|
||||
$message = nl2br(htmlspecialchars($e['message'], $flags, $this->charset));
|
||||
$content .= sprintf(<<<EOF
|
||||
$content .= sprintf(<<<'EOF'
|
||||
<div class="block_exception clear_fix">
|
||||
<h2><span>%d/%d</span> %s: %s</h2>
|
||||
</div>
|
||||
@@ -196,7 +196,7 @@ EOF;
|
||||
*/
|
||||
public function getStylesheet(FlattenException $exception)
|
||||
{
|
||||
return <<<EOF
|
||||
return <<<'EOF'
|
||||
.sf-reset { font: 11px Verdana, Arial, sans-serif; color: #333 }
|
||||
.sf-reset .clear { clear:both; height:0; font-size:0; line-height:0; }
|
||||
.sf-reset .clear_fix:after { display:block; height:0; clear:both; visibility:hidden; }
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2004-2015 Fabien Potencier
|
||||
Copyright (c) 2004-2016 Fabien Potencier
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
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