mirror of
https://github.com/symfony/debug.git
synced 2026-03-25 09:42:20 +01:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
20c5dad1af | ||
|
|
8f1257608f | ||
|
|
355f12cf08 | ||
|
|
ff6a582db5 | ||
|
|
30d1de52f1 | ||
|
|
dfe71c73cf | ||
|
|
8bc9390ba3 | ||
|
|
95a5aa2b72 | ||
|
|
9cd1287f00 | ||
|
|
01c8bc9bac | ||
|
|
796dd4cd11 | ||
|
|
3e889e0489 | ||
|
|
dfb9bf2e04 | ||
|
|
29a6fd38f3 | ||
|
|
712c58246b | ||
|
|
4ba2bda995 | ||
|
|
24170a0eb7 | ||
|
|
b7c4104ea0 |
@@ -133,6 +133,7 @@ class ErrorHandler
|
||||
unset($context['GLOBALS']);
|
||||
}
|
||||
|
||||
$level &= E_ALL | E_STRICT;
|
||||
$exception = new ContextErrorException(sprintf('%s: %s in %s line %d', isset($this->levels[$level]) ? $this->levels[$level] : $level, $message, $file, $line), 0, $level, $file, $line, $context);
|
||||
|
||||
// Exceptions thrown from error handlers are sometimes not caught by the exception
|
||||
@@ -173,7 +174,7 @@ class ErrorHandler
|
||||
}
|
||||
|
||||
$this->reservedMemory = '';
|
||||
$type = $error['type'];
|
||||
$type = $error['type'] & (E_ALL | E_STRICT);
|
||||
if (0 === $this->level || !in_array($type, array(E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE))) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -92,6 +92,7 @@ class ExceptionHandler
|
||||
foreach ($exception->getHeaders() as $name => $value) {
|
||||
header($name.': '.$value, false);
|
||||
}
|
||||
header('Content-Type: text/html; charset='.$this->charset);
|
||||
}
|
||||
|
||||
echo $this->decorate($this->getContent($exception), $this->getStylesheet($exception));
|
||||
@@ -110,7 +111,7 @@ class ExceptionHandler
|
||||
$exception = FlattenException::create($exception);
|
||||
}
|
||||
|
||||
return new Response($this->decorate($this->getContent($exception), $this->getStylesheet($exception)), $exception->getStatusCode(), $exception->getHeaders());
|
||||
return Response::create($this->decorate($this->getContent($exception), $this->getStylesheet($exception)), $exception->getStatusCode(), $exception->getHeaders())->setCharset($this->charset);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,6 +132,7 @@ class ExceptionHandler
|
||||
}
|
||||
|
||||
$content = '';
|
||||
$flags = PHP_VERSION_ID >= 50400 ? ENT_QUOTES | ENT_SUBSTITUTE : ENT_QUOTES;
|
||||
if ($this->debug) {
|
||||
try {
|
||||
$count = count($exception->getAllPrevious());
|
||||
@@ -138,7 +140,7 @@ class ExceptionHandler
|
||||
foreach ($exception->toArray() as $position => $e) {
|
||||
$ind = $count - $position + 1;
|
||||
$class = $this->abbrClass($e['class']);
|
||||
$message = nl2br($e['message']);
|
||||
$message = nl2br(htmlspecialchars($e['message'], $flags, $this->charset));
|
||||
$content .= sprintf(<<<EOF
|
||||
<div class="block_exception clear_fix">
|
||||
<h2><span>%d/%d</span> %s: %s</h2>
|
||||
@@ -155,10 +157,11 @@ EOF
|
||||
}
|
||||
if (isset($trace['file']) && isset($trace['line'])) {
|
||||
if ($linkFormat = ini_get('xdebug.file_link_format')) {
|
||||
$link = str_replace(array('%f', '%l'), array($trace['file'], $trace['line']), $linkFormat);
|
||||
$content .= sprintf(' in <a href="%s" title="Go to source">%s line %s</a>', $link, $trace['file'], $trace['line']);
|
||||
$link = strtr($linkFormat, array('%f' => $trace['file'], '%l' => $trace['line']));
|
||||
$link = htmlspecialchars($link, $flags, $this->charset);
|
||||
$content .= sprintf(' in <a href="%s" title="Go to source">%s line %d</a>', $link, htmlspecialchars($trace['file'], $flags, $this->charset), $trace['line']);
|
||||
} else {
|
||||
$content .= sprintf(' in %s line %s', $trace['file'], $trace['line']);
|
||||
$content .= sprintf(' in %s line %d', htmlspecialchars($trace['file'], $flags, $this->charset), $trace['line']);
|
||||
}
|
||||
}
|
||||
$content .= "</li>\n";
|
||||
@@ -169,7 +172,7 @@ EOF
|
||||
} catch (\Exception $e) {
|
||||
// something nasty happened and we cannot throw an exception anymore
|
||||
if ($this->debug) {
|
||||
$title = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage());
|
||||
$title = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), htmlspecialchars($e->getMessage(), $flags, $this->charset));
|
||||
} else {
|
||||
$title = 'Whoops, looks like something went wrong.';
|
||||
}
|
||||
@@ -276,7 +279,7 @@ EOF;
|
||||
{
|
||||
$parts = explode('\\', $class);
|
||||
|
||||
return sprintf("<abbr title=\"%s\">%s</abbr>", $class, array_pop($parts));
|
||||
return sprintf('<abbr title="%s">%s</abbr>', $class, array_pop($parts));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -296,9 +299,9 @@ EOF;
|
||||
$result = array();
|
||||
foreach ($args as $key => $item) {
|
||||
if ('object' === $item[0]) {
|
||||
$formattedValue = sprintf("<em>object</em>(%s)", $this->abbrClass($item[1]));
|
||||
$formattedValue = sprintf('<em>object</em>(%s)', $this->abbrClass($item[1]));
|
||||
} elseif ('array' === $item[0]) {
|
||||
$formattedValue = sprintf("<em>array</em>(%s)", is_array($item[1]) ? $this->formatArgs($item[1]) : $item[1]);
|
||||
$formattedValue = sprintf('<em>array</em>(%s)', is_array($item[1]) ? $this->formatArgs($item[1]) : $item[1]);
|
||||
} elseif ('string' === $item[0]) {
|
||||
$formattedValue = sprintf("'%s'", htmlspecialchars($item[1], $flags, $this->charset));
|
||||
} elseif ('null' === $item[0]) {
|
||||
|
||||
@@ -40,5 +40,5 @@ Resources
|
||||
You can run the unit tests with the following command:
|
||||
|
||||
$ cd path/to/Symfony/Component/Debug/
|
||||
$ composer.phar install --dev
|
||||
$ composer install
|
||||
$ phpunit
|
||||
|
||||
@@ -26,19 +26,23 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
protected $errorReporting;
|
||||
|
||||
public function setUp()
|
||||
protected function setUp()
|
||||
{
|
||||
$this->errorReporting = error_reporting(E_ALL | E_STRICT);
|
||||
$this->iniSet('display_errors', '1');
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
protected function tearDown()
|
||||
{
|
||||
error_reporting($this->errorReporting);
|
||||
}
|
||||
|
||||
public function testCompileTimeError()
|
||||
{
|
||||
if (defined('HHVM_VERSION')) {
|
||||
$this->markTestSkipped('HHVM does not trigger strict notices.');
|
||||
}
|
||||
|
||||
// the ContextErrorException must not be loaded to test the workaround
|
||||
// for https://bugs.php.net/bug.php?id=65322.
|
||||
if (class_exists('Symfony\Component\Debug\Exception\ContextErrorException', false)) {
|
||||
@@ -59,9 +63,14 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
$that = $this;
|
||||
$exceptionCheck = function ($exception) use ($that) {
|
||||
$that->assertInstanceOf('Symfony\Component\Debug\Exception\ContextErrorException', $exception);
|
||||
$that->assertEquals(E_STRICT, $exception->getSeverity());
|
||||
$that->assertEquals(2, $exception->getLine());
|
||||
$that->assertStringStartsWith('Runtime Notice: Declaration of _CompileTimeError::foo() should be compatible with', $exception->getMessage());
|
||||
if (PHP_VERSION_ID < 70000) {
|
||||
$that->assertEquals(E_STRICT, $exception->getSeverity());
|
||||
$that->assertStringStartsWith('Runtime Notice: Declaration', $exception->getMessage());
|
||||
} else {
|
||||
$that->assertEquals(E_WARNING, $exception->getSeverity());
|
||||
$that->assertStringStartsWith('Warning: Declaration', $exception->getMessage());
|
||||
}
|
||||
$that->assertArrayHasKey('bar', $exception->getContext());
|
||||
};
|
||||
|
||||
@@ -102,7 +111,7 @@ PHP
|
||||
$that->assertEquals(E_NOTICE, $exception->getSeverity());
|
||||
$that->assertEquals(__LINE__ + 40, $exception->getLine());
|
||||
$that->assertEquals(__FILE__, $exception->getFile());
|
||||
$that->assertRegexp('/^Notice: Undefined variable: (foo|bar)/', $exception->getMessage());
|
||||
$that->assertRegExp('/^Notice: Undefined variable: (foo|bar)/', $exception->getMessage());
|
||||
$that->assertArrayHasKey('foobar', $exception->getContext());
|
||||
|
||||
$trace = $exception->getTrace();
|
||||
|
||||
@@ -189,9 +189,9 @@ class FlattenExceptionTest extends \PHPUnit_Framework_TestCase
|
||||
public function testTooBigArray()
|
||||
{
|
||||
$a = array();
|
||||
for ($i = 0; $i < 20; $i++) {
|
||||
for ($j = 0; $j < 50; $j++) {
|
||||
for ($k = 0; $k < 10; $k++) {
|
||||
for ($i = 0; $i < 20; ++$i) {
|
||||
for ($j = 0; $j < 50; ++$j) {
|
||||
for ($k = 0; $k < 10; ++$k) {
|
||||
$a[$i][$j][$k] = 'value';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"type": "library",
|
||||
"description": "Symfony Debug Component",
|
||||
"keywords": [],
|
||||
"homepage": "http://symfony.com",
|
||||
"homepage": "https://symfony.com",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
@@ -12,7 +12,7 @@
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "http://symfony.com/contributors"
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
@@ -22,6 +22,7 @@
|
||||
"symfony/http-kernel": ">=2.3,<2.3.24|~2.4.0|>=2.5,<2.5.9|>=2.6,<2.6.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/phpunit-bridge": "~2.7",
|
||||
"symfony/http-kernel": "~2.3.24|~2.5.9|~2.6,>=2.6.2",
|
||||
"symfony/http-foundation": "~2.1"
|
||||
},
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
bootstrap="vendor/autoload.php"
|
||||
>
|
||||
<php>
|
||||
<!-- Silence E_USER_DEPRECATED (-16385 == -1 & ~E_USER_DEPRECATED) -->
|
||||
<ini name="error_reporting" value="-16385"/>
|
||||
<ini name="error_reporting" value="-1" />
|
||||
</php>
|
||||
<testsuites>
|
||||
<testsuite name="Symfony Debug Component Test Suite">
|
||||
|
||||
Reference in New Issue
Block a user