Compare commits

..

5 Commits
v2.3.36 ... 2.3

Author SHA1 Message Date
Nicolas Grekas
863d29c31a [Debug] Fix handling of php7 throwables 2016-03-30 11:02:35 +02:00
Konstantin.Myakshin
a6f7b78e40 Use constant instead of function call. 2016-03-04 15:04:09 +02:00
Javier Eguiluz
9233292b81 Updated all the README files 2016-03-04 08:12:06 +01:00
Diego Saint Esteben
7cca5bb1b1 Update copyright year 2016-01-01 23:53:47 -03:00
Gregor Harlan
d0ee40c1e2 use nowdoc instead of heredoc 2015-12-21 17:05:00 +01:00
5 changed files with 40 additions and 41 deletions

View File

@@ -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);

View File

@@ -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']);

View File

@@ -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; }

View File

@@ -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

View File

@@ -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)