Skip to content

Commit

Permalink
bug #17819 [HttpKernel] Prevent a fatal error when DebugHandlersListe…
Browse files Browse the repository at this point in the history
…ner is used with a kernel with no terminateWithException() method (jakzal)

This PR was merged into the 2.7 branch.

Discussion
----------

[HttpKernel] Prevent a fatal error when DebugHandlersListener is used with a kernel with no terminateWithException() method

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

I just suffered from this bug on a project that used HttpKernelInterface implementation with no `terminateWithException() method (which is not part of the interface).

Commits
-------

2849152 [HttpKernel] Prevent a fatal error when DebugHandlersListener is used with a kernel with no terminateWithException() method
  • Loading branch information
fabpot committed Feb 17, 2016
2 parents 1c79c7b + 2849152 commit a515383
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Expand Up @@ -93,7 +93,9 @@ public function configure(Event $event = null)
}
if (!$this->exceptionHandler) {
if ($event instanceof KernelEvent) {
$this->exceptionHandler = array($event->getKernel(), 'terminateWithException');
if (method_exists($event->getKernel(), 'terminateWithException')) {
$this->exceptionHandler = array($event->getKernel(), 'terminateWithException');
}
} elseif ($event instanceof ConsoleEvent && $app = $event->getCommand()->getApplication()) {
$output = $event->getOutput();
if ($output instanceof ConsoleOutputInterface) {
Expand Down
Expand Up @@ -21,7 +21,10 @@
use Symfony\Component\Debug\ErrorHandler;
use Symfony\Component\Debug\ExceptionHandler;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\KernelEvent;
use Symfony\Component\HttpKernel\EventListener\DebugHandlersListener;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelEvents;

/**
Expand Down Expand Up @@ -62,6 +65,31 @@ public function testConfigure()
$this->assertSame(array($logger, LogLevel::INFO), $loggers[E_DEPRECATED]);
}

public function testConfigureForHttpKernelWithNoTerminateWithException()
{
$listener = new DebugHandlersListener(null);
$eHandler = new ErrorHandler();
$event = new KernelEvent(
$this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'),
Request::create('/'),
HttpKernelInterface::MASTER_REQUEST
);

$exception = null;
$h = set_exception_handler(array($eHandler, 'handleException'));
try {
$listener->configure($event);
} catch (\Exception $exception) {
}
restore_exception_handler();

if (null !== $exception) {
throw $exception;
}

$this->assertNull($h);
}

public function testConsoleEvent()
{
$dispatcher = new EventDispatcher();
Expand Down

0 comments on commit a515383

Please sign in to comment.