Skip to content

Commit d4f4dab

Browse files
[HttpKernel] fix DebugHandlersListener
1 parent 2ef1279 commit d4f4dab

File tree

2 files changed

+26
-29
lines changed

2 files changed

+26
-29
lines changed

EventListener/DebugHandlersListener.php

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Symfony\Component\Debug\ErrorHandler;
1616
use Symfony\Component\Debug\ExceptionHandler;
1717
use Symfony\Component\EventDispatcher\Event;
18-
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
1918
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
2019
use Symfony\Component\HttpKernel\Event\KernelEvent;
2120
use Symfony\Component\HttpKernel\KernelEvents;
@@ -36,6 +35,7 @@ class DebugHandlersListener implements EventSubscriberInterface
3635
private $throwAt;
3736
private $scream;
3837
private $fileLinkFormat;
38+
private $firstCall = true;
3939

4040
/**
4141
* @param callable|null $exceptionHandler A handler that will be called on Exception
@@ -58,38 +58,37 @@ public function __construct($exceptionHandler, LoggerInterface $logger = null, $
5858
/**
5959
* Configures the error handler.
6060
*
61-
* @param Event|null $event The triggering event
62-
* @param string|null $eventName The triggering event name
63-
* @param EventDispatcherInterface|null $eventDispatcher The dispatcher used to trigger $event
61+
* @param Event|null $event The triggering event
6462
*/
65-
public function configure(Event $event = null, $eventName = null, EventDispatcherInterface $eventDispatcher = null)
63+
public function configure(Event $event = null)
6664
{
67-
if (null !== $eventDispatcher) {
68-
foreach (array_keys(static::getSubscribedEvents()) as $name) {
69-
$eventDispatcher->removeListener($name, array($this, 'configure'));
70-
}
65+
if (!$this->firstCall) {
66+
return;
7167
}
72-
$handler = set_error_handler('var_dump', 0);
73-
$handler = is_array($handler) ? $handler[0] : null;
74-
restore_error_handler();
75-
if ($handler instanceof ErrorHandler) {
76-
if ($this->logger) {
77-
$handler->setDefaultLogger($this->logger, $this->levels);
78-
if (is_array($this->levels)) {
79-
$scream = 0;
80-
foreach ($this->levels as $type => $log) {
81-
$scream |= $type;
68+
$this->firstCall = false;
69+
if ($this->logger || null !== $this->throwAt) {
70+
$handler = set_error_handler('var_dump', 0);
71+
$handler = is_array($handler) ? $handler[0] : null;
72+
restore_error_handler();
73+
if ($handler instanceof ErrorHandler) {
74+
if ($this->logger) {
75+
$handler->setDefaultLogger($this->logger, $this->levels);
76+
if (is_array($this->levels)) {
77+
$scream = 0;
78+
foreach ($this->levels as $type => $log) {
79+
$scream |= $type;
80+
}
81+
} else {
82+
$scream = null === $this->levels ? E_ALL | E_STRICT : $this->levels;
8283
}
83-
} else {
84-
$scream = null === $this->levels ? E_ALL | E_STRICT : $this->levels;
84+
if ($this->scream) {
85+
$handler->screamAt($scream);
86+
}
87+
$this->logger = $this->levels = null;
8588
}
86-
if ($this->scream) {
87-
$handler->screamAt($scream);
89+
if (null !== $this->throwAt) {
90+
$handler->throwAt($this->throwAt, true);
8891
}
89-
$this->logger = $this->levels = null;
90-
}
91-
if (null !== $this->throwAt) {
92-
$handler->throwAt($this->throwAt, true);
9392
}
9493
}
9594
if (!$this->exceptionHandler) {

Tests/EventListener/DebugHandlersListenerTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ public function testConsoleEvent()
9595
throw $exception;
9696
}
9797

98-
$this->assertSame(array(), $dispatcher->getListeners());
99-
10098
$xHandler = $eHandler->setExceptionHandler('var_dump');
10199
$this->assertInstanceOf('Closure', $xHandler);
102100

0 commit comments

Comments
 (0)