Skip to content

Commit a6e5a71

Browse files
[Debug] update FrameworkBundle and HttpKernel for new ErrorHandler
1 parent 7a0ab29 commit a6e5a71

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
2.6.0
5+
-----
6+
7+
* deprecated `Symfony\Component\HttpKernel\EventListener\ErrorsLoggerListener`, use `Symfony\Component\HttpKernel\EventListener\DebugHandlersListener` instead
8+
49
2.5.0
510
-----
611

EventListener/DebugHandlersListener.php

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,72 @@
1111

1212
namespace Symfony\Component\HttpKernel\EventListener;
1313

14-
use Symfony\Component\Debug\ExceptionHandler;
14+
use Psr\Log\LoggerInterface;
15+
use Symfony\Component\Debug\ErrorHandler;
16+
use Symfony\Component\Debug\AbstractExceptionHandler;
1517
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1618
use Symfony\Component\HttpKernel\KernelEvents;
1719

1820
/**
19-
* Configures the ExceptionHandler.
21+
* Configures errors and exceptions handlers.
2022
*
2123
* @author Nicolas Grekas <[email protected]>
2224
*/
2325
class DebugHandlersListener implements EventSubscriberInterface
2426
{
2527
private $exceptionHandler;
28+
private $logger;
29+
private $levels;
30+
private $debug;
2631

27-
public function __construct($exceptionHandler)
32+
/**
33+
* @param callable $exceptionHandler A handler that will be called on Exception
34+
* @param LoggerInterface|null $logger A PSR-3 logger
35+
* @param array|int $levels An array map of E_* to LogLevel::* or an integer bit field of E_* constants
36+
* @param bool $debug Enables/disables debug mode
37+
*/
38+
public function __construct($exceptionHandler, LoggerInterface $logger = null, $levels = null, $debug = true)
2839
{
2940
if (is_callable($exceptionHandler)) {
3041
$this->exceptionHandler = $exceptionHandler;
3142
}
43+
$this->logger = $logger;
44+
$this->levels = $levels;
45+
$this->debug = $debug;
3246
}
3347

3448
public function configure()
3549
{
50+
if ($this->logger) {
51+
$handler = set_error_handler('var_dump', 0);
52+
$handler = is_array($handler) ? $handler[0] : null;
53+
restore_error_handler();
54+
if ($handler instanceof ErrorHandler) {
55+
if ($this->debug) {
56+
$handler->throwAt(-1);
57+
}
58+
$handler->setDefaultLogger($this->logger, $this->levels);
59+
if (is_array($this->levels)) {
60+
$scream = 0;
61+
foreach ($this->levels as $type => $log) {
62+
$scream |= $type;
63+
}
64+
$this->levels = $scream;
65+
}
66+
$handler->screamAt($this->levels);
67+
}
68+
$this->logger = $this->levels = null;
69+
}
3670
if ($this->exceptionHandler) {
3771
$handler = set_exception_handler('var_dump');
3872
$handler = is_array($handler) ? $handler[0] : null;
3973
restore_exception_handler();
40-
if ($handler instanceof ExceptionHandler) {
74+
if ($handler instanceof ErrorHandler) {
75+
$h = $handler->setExceptionHandler('var_dump') ?: $this->exceptionHandler;
76+
$handler->setExceptionHandler($h);
77+
$handler = is_array($h) ? $h[0] : null;
78+
}
79+
if ($handler instanceof AbstractExceptionHandler) {
4180
$handler->setHandler($this->exceptionHandler);
4281
}
4382
$this->exceptionHandler = null;

EventListener/ErrorsLoggerListener.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
*
2222
* @author Colin Frei <[email protected]>
2323
* @author Konstantin Myakshin <[email protected]>
24+
*
25+
* @deprecated since 2.6, to be removed in 3.0. Use DebugHandlersListener instead.
2426
*/
2527
class ErrorsLoggerListener implements EventSubscriberInterface
2628
{

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"php": ">=5.3.3",
2020
"symfony/event-dispatcher": "~2.5",
2121
"symfony/http-foundation": "~2.4",
22-
"symfony/debug": "~2.5",
22+
"symfony/debug": "~2.6",
2323
"psr/log": "~1.0"
2424
},
2525
"require-dev": {

0 commit comments

Comments
 (0)