diff --git a/CHANGELOG.md b/CHANGELOG.md index 5be8195dc4..25f431395b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 ----- diff --git a/DataCollector/AjaxDataCollector.php b/DataCollector/AjaxDataCollector.php index 370a874fe5..86ca6963e4 100644 --- a/DataCollector/AjaxDataCollector.php +++ b/DataCollector/AjaxDataCollector.php @@ -18,6 +18,8 @@ * AjaxDataCollector. * * @author Bart van den Burg + * + * @final since Symfony 4.4 */ class AjaxDataCollector extends DataCollector { diff --git a/DataCollector/ConfigDataCollector.php b/DataCollector/ConfigDataCollector.php index 2ab3048ed2..88173df54b 100644 --- a/DataCollector/ConfigDataCollector.php +++ b/DataCollector/ConfigDataCollector.php @@ -19,6 +19,8 @@ /** * @author Fabien Potencier + * + * @final since Symfony 4.4 */ class ConfigDataCollector extends DataCollector implements LateDataCollectorInterface { diff --git a/DataCollector/EventDataCollector.php b/DataCollector/EventDataCollector.php index b9f805415d..c5d7875af1 100644 --- a/DataCollector/EventDataCollector.php +++ b/DataCollector/EventDataCollector.php @@ -22,6 +22,8 @@ * EventDataCollector. * * @author Fabien Potencier + * + * @final since Symfony 4.4 */ class EventDataCollector extends DataCollector implements LateDataCollectorInterface { diff --git a/DataCollector/ExceptionDataCollector.php b/DataCollector/ExceptionDataCollector.php index 09d6e4b472..08e79c53e1 100644 --- a/DataCollector/ExceptionDataCollector.php +++ b/DataCollector/ExceptionDataCollector.php @@ -19,6 +19,8 @@ * ExceptionDataCollector. * * @author Fabien Potencier + * + * @final since Symfony 4.4 */ class ExceptionDataCollector extends DataCollector { diff --git a/DataCollector/LoggerDataCollector.php b/DataCollector/LoggerDataCollector.php index d91f77cc33..e3e587927a 100644 --- a/DataCollector/LoggerDataCollector.php +++ b/DataCollector/LoggerDataCollector.php @@ -21,6 +21,8 @@ * LogDataCollector. * * @author Fabien Potencier + * + * @final since Symfony 4.4 */ class LoggerDataCollector extends DataCollector implements LateDataCollectorInterface { diff --git a/DataCollector/MemoryDataCollector.php b/DataCollector/MemoryDataCollector.php index c101fe406a..ff64b56ab0 100644 --- a/DataCollector/MemoryDataCollector.php +++ b/DataCollector/MemoryDataCollector.php @@ -18,6 +18,8 @@ * MemoryDataCollector. * * @author Fabien Potencier + * + * @final since Symfony 4.4 */ class MemoryDataCollector extends DataCollector implements LateDataCollectorInterface { diff --git a/DataCollector/RequestDataCollector.php b/DataCollector/RequestDataCollector.php index 85107801a1..4d9ba11280 100644 --- a/DataCollector/RequestDataCollector.php +++ b/DataCollector/RequestDataCollector.php @@ -22,6 +22,8 @@ /** * @author Fabien Potencier + * + * @final since Symfony 4.4 */ class RequestDataCollector extends DataCollector implements EventSubscriberInterface, LateDataCollectorInterface { diff --git a/DataCollector/RouterDataCollector.php b/DataCollector/RouterDataCollector.php index 461d796cb3..c6f773a947 100644 --- a/DataCollector/RouterDataCollector.php +++ b/DataCollector/RouterDataCollector.php @@ -33,6 +33,8 @@ public function __construct() /** * {@inheritdoc} + * + * @final since Symfony 4.4 */ public function collect(Request $request, Response $response, \Exception $exception = null) { diff --git a/DataCollector/TimeDataCollector.php b/DataCollector/TimeDataCollector.php index cb490c2bb3..744bab2212 100644 --- a/DataCollector/TimeDataCollector.php +++ b/DataCollector/TimeDataCollector.php @@ -19,6 +19,8 @@ /** * @author Fabien Potencier + * + * @final since Symfony 4.4 */ class TimeDataCollector extends DataCollector implements LateDataCollectorInterface { diff --git a/EventListener/DebugHandlersListener.php b/EventListener/DebugHandlersListener.php index 5e2e847b15..4905ff0c56 100644 --- a/EventListener/DebugHandlersListener.php +++ b/EventListener/DebugHandlersListener.php @@ -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); + } }; } } diff --git a/HttpKernel.php b/HttpKernel.php index c0ca97f920..e92bcd38da 100644 --- a/HttpKernel.php +++ b/HttpKernel.php @@ -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); } } @@ -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(); @@ -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); diff --git a/Profiler/Profiler.php b/Profiler/Profiler.php index 6a32d5af21..463e615125 100644 --- a/Profiler/Profiler.php +++ b/Profiler/Profiler.php @@ -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; } diff --git a/Tests/EventListener/DebugHandlersListenerTest.php b/Tests/EventListener/DebugHandlersListenerTest.php index b8ec8f3e73..6f04c0a4c6 100644 --- a/Tests/EventListener/DebugHandlersListenerTest.php +++ b/Tests/EventListener/DebugHandlersListenerTest.php @@ -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; @@ -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()); }