Skip to content

Commit

Permalink
Merge branch '4.4'
Browse files Browse the repository at this point in the history
* 4.4:
  [Messenger] use events consistently in worker
  Deprecate things that prevent \Throwable from bubbling down
  • Loading branch information
nicolas-grekas committed Nov 5, 2019
2 parents 7f00987 + ea37f12 commit 0cb1347
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -42,6 +42,12 @@ CHANGELOG
* Marked all dispatched event classes as `@final`
* Added `ErrorController` to enable the preview and error rendering mechanism
* Getting the container from a non-booted kernel is deprecated.
* Marked the `AjaxDataCollector`, `ConfigDataCollector`, `EventDataCollector`,
`ExceptionDataCollector`, `LoggerDataCollector`, `MemoryDataCollector`,
`RequestDataCollector` and `TimeDataCollector` classes as `@final`.
* Marked the `RouterDataCollector::collect()` method as `@final`.
* The `DataCollectorInterface::collect()` and `Profiler::collect()` methods third parameter signature
will be `\Throwable $exception = null` instead of `\Exception $exception = null` in Symfony 5.0.

4.3.0
-----
Expand Down
2 changes: 2 additions & 0 deletions DataCollector/AjaxDataCollector.php
Expand Up @@ -18,6 +18,8 @@
* AjaxDataCollector.
*
* @author Bart van den Burg <bart@burgov.nl>
*
* @final since Symfony 4.4
*/
class AjaxDataCollector extends DataCollector
{
Expand Down
2 changes: 2 additions & 0 deletions DataCollector/ConfigDataCollector.php
Expand Up @@ -19,6 +19,8 @@

/**
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
*/
class ConfigDataCollector extends DataCollector implements LateDataCollectorInterface
{
Expand Down
2 changes: 2 additions & 0 deletions DataCollector/EventDataCollector.php
Expand Up @@ -22,6 +22,8 @@
* EventDataCollector.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
*/
class EventDataCollector extends DataCollector implements LateDataCollectorInterface
{
Expand Down
2 changes: 2 additions & 0 deletions DataCollector/ExceptionDataCollector.php
Expand Up @@ -19,6 +19,8 @@
* ExceptionDataCollector.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
*/
class ExceptionDataCollector extends DataCollector
{
Expand Down
2 changes: 2 additions & 0 deletions DataCollector/LoggerDataCollector.php
Expand Up @@ -21,6 +21,8 @@
* LogDataCollector.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
*/
class LoggerDataCollector extends DataCollector implements LateDataCollectorInterface
{
Expand Down
2 changes: 2 additions & 0 deletions DataCollector/MemoryDataCollector.php
Expand Up @@ -18,6 +18,8 @@
* MemoryDataCollector.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
*/
class MemoryDataCollector extends DataCollector implements LateDataCollectorInterface
{
Expand Down
2 changes: 2 additions & 0 deletions DataCollector/RequestDataCollector.php
Expand Up @@ -22,6 +22,8 @@

/**
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
*/
class RequestDataCollector extends DataCollector implements EventSubscriberInterface, LateDataCollectorInterface
{
Expand Down
2 changes: 2 additions & 0 deletions DataCollector/RouterDataCollector.php
Expand Up @@ -33,6 +33,8 @@ public function __construct()

/**
* {@inheritdoc}
*
* @final since Symfony 4.4
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
{
Expand Down
2 changes: 2 additions & 0 deletions DataCollector/TimeDataCollector.php
Expand Up @@ -19,6 +19,8 @@

/**
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since Symfony 4.4
*/
class TimeDataCollector extends DataCollector implements LateDataCollectorInterface
{
Expand Down
12 changes: 8 additions & 4 deletions EventListener/DebugHandlersListener.php
Expand Up @@ -125,11 +125,15 @@ public function configure(object $event = null)
$output = $output->getErrorOutput();
}
$this->exceptionHandler = static function (\Throwable $e) use ($app, $output) {
if (!$e instanceof \Exception) {
$e = new ErrorException($e);
}
if (method_exists($app, 'renderThrowable')) {
$app->renderThrowable($e, $output);
} else {
if (!$e instanceof \Exception) {
$e = new ErrorException($e);
}

$app->renderException($e, $output);
$app->renderException($e, $output);
}
};
}
}
Expand Down
10 changes: 5 additions & 5 deletions HttpKernel.php
Expand Up @@ -75,7 +75,7 @@ public function handle(Request $request, int $type = HttpKernelInterface::MASTER
throw $e;
}

return $this->handleException($e, $request, $type);
return $this->handleThrowable($e, $request, $type);
}
}

Expand All @@ -90,13 +90,13 @@ public function terminate(Request $request, Response $response)
/**
* @internal
*/
public function terminateWithException(\Exception $exception, Request $request = null)
public function terminateWithException(\Throwable $exception, Request $request = null)
{
if (!$request = $request ?: $this->requestStack->getMasterRequest()) {
throw $exception;
}

$response = $this->handleException($exception, $request, self::MASTER_REQUEST);
$response = $this->handleThrowable($exception, $request, self::MASTER_REQUEST);

$response->sendHeaders();
$response->sendContent();
Expand Down Expand Up @@ -196,11 +196,11 @@ private function finishRequest(Request $request, int $type)
}

/**
* Handles an exception by trying to convert it to a Response.
* Handles a throwable by trying to convert it to a Response.
*
* @throws \Exception
*/
private function handleException(\Exception $e, Request $request, int $type): Response
private function handleThrowable(\Throwable $e, Request $request, int $type): Response
{
$event = new ExceptionEvent($this, $request, $type, $e);
$this->dispatcher->dispatch($event, KernelEvents::EXCEPTION);
Expand Down
6 changes: 5 additions & 1 deletion Profiler/Profiler.php
Expand Up @@ -132,10 +132,14 @@ public function find(?string $ip, ?string $url, ?string $limit, ?string $method,
/**
* Collects data for the given Response.
*
* @param \Throwable|null $exception
*
* @return Profile|null A Profile instance or null if the profiler is disabled
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
{
$exception = 2 < \func_num_args() ? func_get_arg(2) : null;

if (false === $this->enabled) {
return null;
}
Expand Down
3 changes: 2 additions & 1 deletion Tests/EventListener/DebugHandlersListenerTest.php
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\TestCase;
use Psr\Log\LogLevel;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Console\Event\ConsoleEvent;
Expand Down Expand Up @@ -123,7 +124,7 @@ public function testConsoleEvent()
$this->assertInstanceOf('Closure', $xHandler);

$app->expects($this->once())
->method('renderException');
->method(method_exists(Application::class, 'renderThrowable') ? 'renderThrowable' : 'renderException');

$xHandler(new \Exception());
}
Expand Down

0 comments on commit 0cb1347

Please sign in to comment.