From 7dd9dbf28d07afc1d261a50cf581d4d9a579d66b Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 27 Jun 2019 15:32:52 +0200 Subject: [PATCH 1/2] [ErrorHandler] made IDEs and static analysis tools happy --- .../Component/ErrorCatcher/ErrorRenderer/ErrorRenderer.php | 2 +- src/Symfony/Component/ErrorCatcher/ExceptionHandler.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/ErrorCatcher/ErrorRenderer/ErrorRenderer.php b/src/Symfony/Component/ErrorCatcher/ErrorRenderer/ErrorRenderer.php index 76b823fb41eb0..1d326bde88d74 100644 --- a/src/Symfony/Component/ErrorCatcher/ErrorRenderer/ErrorRenderer.php +++ b/src/Symfony/Component/ErrorCatcher/ErrorRenderer/ErrorRenderer.php @@ -62,7 +62,7 @@ public function render($exception, string $format = 'html'): string throw new ErrorRendererNotFoundException(sprintf('No error renderer found for format "%s".', $format)); } - if (!$exception instanceof FlattenException) { + if ($exception instanceof \Exception) { $exception = FlattenException::create($exception); } diff --git a/src/Symfony/Component/ErrorCatcher/ExceptionHandler.php b/src/Symfony/Component/ErrorCatcher/ExceptionHandler.php index 63b36d29d4011..0e456d6a84b7a 100644 --- a/src/Symfony/Component/ErrorCatcher/ExceptionHandler.php +++ b/src/Symfony/Component/ErrorCatcher/ExceptionHandler.php @@ -160,7 +160,7 @@ public function handle(\Exception $exception) */ public function sendPhpResponse($exception) { - if (!$exception instanceof FlattenException) { + if ($exception instanceof \Exception) { $exception = FlattenException::create($exception); } From f511bc5ff6c5fcc2ed1696376d68c402c1301788 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 27 Jun 2019 15:50:24 +0200 Subject: [PATCH 2/2] deprecated FlattenException::create() --- .../Controller/PreviewErrorController.php | 2 +- .../Controller/ExceptionControllerTest.php | 8 +-- .../Debug/Exception/FlattenException.php | 9 +++ .../ErrorRenderer/ErrorRenderer.php | 6 +- .../ErrorRenderer/HtmlErrorRenderer.php | 2 +- .../Exception/FlattenException.php | 5 -- .../ErrorCatcher/ExceptionHandler.php | 6 +- .../DependencyInjection/ErrorRendererTest.php | 4 +- .../Tests/ErrorRenderer/ErrorRendererTest.php | 6 +- .../ErrorRenderer/HtmlErrorRendererTest.php | 2 +- .../ErrorRenderer/JsonErrorRendererTest.php | 2 +- .../ErrorRenderer/TxtErrorRendererTest.php | 2 +- .../ErrorRenderer/XmlErrorRendererTest.php | 2 +- .../Tests/Exception/FlattenExceptionTest.php | 68 +++++++++---------- .../DataCollector/ExceptionDataCollector.php | 2 +- .../EventListener/ExceptionListener.php | 6 +- .../ExceptionDataCollectorTest.php | 2 +- 17 files changed, 69 insertions(+), 65 deletions(-) diff --git a/src/Symfony/Bundle/TwigBundle/Controller/PreviewErrorController.php b/src/Symfony/Bundle/TwigBundle/Controller/PreviewErrorController.php index 427e6996f887c..70f3d99df419f 100644 --- a/src/Symfony/Bundle/TwigBundle/Controller/PreviewErrorController.php +++ b/src/Symfony/Bundle/TwigBundle/Controller/PreviewErrorController.php @@ -35,7 +35,7 @@ public function __construct(HttpKernelInterface $kernel, $controller) public function previewErrorPageAction(Request $request, $code) { - $exception = FlattenException::create(new \Exception('Something has intentionally gone wrong.'), $code); + $exception = FlattenException::createFromThrowable(new \Exception('Something has intentionally gone wrong.'), $code); /* * This Request mimics the parameters set by diff --git a/src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php b/src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php index 9301fe37e5bf6..1c32b6e2c5af8 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php @@ -26,7 +26,7 @@ public function testShowActionCanBeForcedToShowErrorPage() $request = $this->createRequest('html'); $request->attributes->set('showException', false); - $exception = FlattenException::create(new \Exception(), 404); + $exception = FlattenException::createFromThrowable(new \Exception(), 404); $controller = new ExceptionController($twig, /* "showException" defaults to --> */ true); $response = $controller->showAction($request, $exception, null); @@ -40,7 +40,7 @@ public function testFallbackToHtmlIfNoTemplateForRequestedFormat() $twig = $this->createTwigEnv(['@Twig/Exception/error.html.twig' => '']); $request = $this->createRequest('txt'); - $exception = FlattenException::create(new \Exception()); + $exception = FlattenException::createFromThrowable(new \Exception()); $controller = new ExceptionController($twig, false); $controller->showAction($request, $exception); @@ -54,7 +54,7 @@ public function testFallbackToHtmlWithFullExceptionIfNoTemplateForRequestedForma $request = $this->createRequest('txt'); $request->attributes->set('showException', true); - $exception = FlattenException::create(new \Exception()); + $exception = FlattenException::createFromThrowable(new \Exception()); $controller = new ExceptionController($twig, false); $controller->showAction($request, $exception); @@ -67,7 +67,7 @@ public function testResponseHasRequestedMimeType() $twig = $this->createTwigEnv(['@Twig/Exception/error.json.twig' => '{}']); $request = $this->createRequest('json'); - $exception = FlattenException::create(new \Exception()); + $exception = FlattenException::createFromThrowable(new \Exception()); $controller = new ExceptionController($twig, false); $response = $controller->showAction($request, $exception); diff --git a/src/Symfony/Component/Debug/Exception/FlattenException.php b/src/Symfony/Component/Debug/Exception/FlattenException.php index 70ecd966e48d2..748e2c601186f 100644 --- a/src/Symfony/Component/Debug/Exception/FlattenException.php +++ b/src/Symfony/Component/Debug/Exception/FlattenException.php @@ -20,4 +20,13 @@ */ class FlattenException extends BaseFlattenException { + /** + * @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Exception::createFromThrowable() instead. + */ + public static function create(\Exception $exception, $statusCode = null, array $headers = []): self + { + @trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Exception::createFromThrowable() instead.', __METHOD__), E_USER_DEPRECATED); + + return parent::createFromThrowable($exception, $statusCode, $headers); + } } diff --git a/src/Symfony/Component/ErrorCatcher/ErrorRenderer/ErrorRenderer.php b/src/Symfony/Component/ErrorCatcher/ErrorRenderer/ErrorRenderer.php index 1d326bde88d74..bf2a1b1d5163c 100644 --- a/src/Symfony/Component/ErrorCatcher/ErrorRenderer/ErrorRenderer.php +++ b/src/Symfony/Component/ErrorCatcher/ErrorRenderer/ErrorRenderer.php @@ -49,7 +49,7 @@ public function addRenderer(ErrorRendererInterface $renderer, string $format): s /** * Renders an Exception and returns the Response content. * - * @param \Exception|FlattenException $exception An \Exception or FlattenException instance + * @param \Throwable|FlattenException $exception A \Throwable or FlattenException instance * @param string $format The request format (html, json, xml, etc.) * * @return string The Response content as a string @@ -62,8 +62,8 @@ public function render($exception, string $format = 'html'): string throw new ErrorRendererNotFoundException(sprintf('No error renderer found for format "%s".', $format)); } - if ($exception instanceof \Exception) { - $exception = FlattenException::create($exception); + if ($exception instanceof \Throwable) { + $exception = FlattenException::createFromThrowable($exception); } return $this->renderers[$format]->render($exception); diff --git a/src/Symfony/Component/ErrorCatcher/ErrorRenderer/HtmlErrorRenderer.php b/src/Symfony/Component/ErrorCatcher/ErrorRenderer/HtmlErrorRenderer.php index 43ca7dabd6bfa..d73fc48b4a86a 100644 --- a/src/Symfony/Component/ErrorCatcher/ErrorRenderer/HtmlErrorRenderer.php +++ b/src/Symfony/Component/ErrorCatcher/ErrorRenderer/HtmlErrorRenderer.php @@ -150,7 +150,7 @@ public function getBody(FlattenException $exception) } catch (\Exception $e) { // something nasty happened and we cannot throw an exception anymore if ($this->debug) { - $e = FlattenException::create($e); + $e = FlattenException::createFromThrowable($e); $exceptionMessage = sprintf('Exception thrown when handling an exception (%s: %s)', $e->getClass(), $this->escapeHtml($e->getMessage())); } else { $exceptionMessage = 'Whoops, looks like something went wrong.'; diff --git a/src/Symfony/Component/ErrorCatcher/Exception/FlattenException.php b/src/Symfony/Component/ErrorCatcher/Exception/FlattenException.php index 27f7ace4bec6e..5f6c81047f94a 100644 --- a/src/Symfony/Component/ErrorCatcher/Exception/FlattenException.php +++ b/src/Symfony/Component/ErrorCatcher/Exception/FlattenException.php @@ -36,11 +36,6 @@ class FlattenException private $file; private $line; - public static function create(\Exception $exception, $statusCode = null, array $headers = []) - { - return static::createFromThrowable($exception, $statusCode, $headers); - } - public static function createFromThrowable(\Throwable $exception, ?int $statusCode = null, array $headers = []): self { $e = new static(); diff --git a/src/Symfony/Component/ErrorCatcher/ExceptionHandler.php b/src/Symfony/Component/ErrorCatcher/ExceptionHandler.php index 0e456d6a84b7a..225db00622e0c 100644 --- a/src/Symfony/Component/ErrorCatcher/ExceptionHandler.php +++ b/src/Symfony/Component/ErrorCatcher/ExceptionHandler.php @@ -156,12 +156,12 @@ public function handle(\Exception $exception) * This method uses plain PHP functions like header() and echo to output * the response. * - * @param \Exception|FlattenException $exception An \Exception or FlattenException instance + * @param \Throwable|FlattenException $exception A \Throwable or FlattenException instance */ public function sendPhpResponse($exception) { - if ($exception instanceof \Exception) { - $exception = FlattenException::create($exception); + if ($exception instanceof \Throwable) { + $exception = FlattenException::createFromThrowable($exception); } if (!headers_sent()) { diff --git a/src/Symfony/Component/ErrorCatcher/Tests/DependencyInjection/ErrorRendererTest.php b/src/Symfony/Component/ErrorCatcher/Tests/DependencyInjection/ErrorRendererTest.php index 747cd5069670e..4fb7799d7552b 100644 --- a/src/Symfony/Component/ErrorCatcher/Tests/DependencyInjection/ErrorRendererTest.php +++ b/src/Symfony/Component/ErrorCatcher/Tests/DependencyInjection/ErrorRendererTest.php @@ -27,7 +27,7 @@ public function testInvalidErrorRenderer() $container = $this->getMockBuilder('Psr\Container\ContainerInterface')->getMock(); $container->expects($this->once())->method('has')->with('foo')->willReturn(false); - $exception = FlattenException::create(new \Exception('Foo')); + $exception = FlattenException::createFromThrowable(new \Exception('Foo')); (new ErrorRenderer($container))->render($exception, 'foo'); } @@ -48,7 +48,7 @@ public function testCustomErrorRenderer() $errorRenderer = new ErrorRenderer($container); - $exception = FlattenException::create(new \RuntimeException('Foo')); + $exception = FlattenException::createFromThrowable(new \RuntimeException('Foo')); $this->assertSame('Foo', $errorRenderer->render($exception, 'foo')); } } diff --git a/src/Symfony/Component/ErrorCatcher/Tests/ErrorRenderer/ErrorRendererTest.php b/src/Symfony/Component/ErrorCatcher/Tests/ErrorRenderer/ErrorRendererTest.php index 156de10c662a0..e839ceb1e24b1 100644 --- a/src/Symfony/Component/ErrorCatcher/Tests/ErrorRenderer/ErrorRendererTest.php +++ b/src/Symfony/Component/ErrorCatcher/Tests/ErrorRenderer/ErrorRendererTest.php @@ -24,7 +24,7 @@ class ErrorRendererTest extends TestCase */ public function testErrorRendererNotFound() { - $exception = FlattenException::create(new \Exception('foo')); + $exception = FlattenException::createFromThrowable(new \Exception('foo')); (new ErrorRenderer([]))->render($exception, 'foo'); } @@ -34,7 +34,7 @@ public function testErrorRendererNotFound() */ public function testInvalidErrorRenderer() { - $exception = FlattenException::create(new \Exception('foo')); + $exception = FlattenException::createFromThrowable(new \Exception('foo')); (new ErrorRenderer([new \stdClass()]))->render($exception, 'foo'); } @@ -43,7 +43,7 @@ public function testCustomErrorRenderer() $renderers = [new FooErrorRenderer()]; $errorRenderer = new ErrorRenderer($renderers); - $exception = FlattenException::create(new \RuntimeException('Foo')); + $exception = FlattenException::createFromThrowable(new \RuntimeException('Foo')); $this->assertSame('Foo', $errorRenderer->render($exception, 'foo')); } } diff --git a/src/Symfony/Component/ErrorCatcher/Tests/ErrorRenderer/HtmlErrorRendererTest.php b/src/Symfony/Component/ErrorCatcher/Tests/ErrorRenderer/HtmlErrorRendererTest.php index 3054e28510bc2..f211df072c553 100644 --- a/src/Symfony/Component/ErrorCatcher/Tests/ErrorRenderer/HtmlErrorRendererTest.php +++ b/src/Symfony/Component/ErrorCatcher/Tests/ErrorRenderer/HtmlErrorRendererTest.php @@ -19,7 +19,7 @@ class HtmlErrorRendererTest extends TestCase { public function testRender() { - $exception = FlattenException::create(new \RuntimeException('Foo')); + $exception = FlattenException::createFromThrowable(new \RuntimeException('Foo')); $expected = '%A%A%AInternal Server Error%A

Foo

%ARuntimeException%A'; $this->assertStringMatchesFormat($expected, (new HtmlErrorRenderer())->render($exception)); diff --git a/src/Symfony/Component/ErrorCatcher/Tests/ErrorRenderer/JsonErrorRendererTest.php b/src/Symfony/Component/ErrorCatcher/Tests/ErrorRenderer/JsonErrorRendererTest.php index bbc754f9094ba..a4782ee264153 100644 --- a/src/Symfony/Component/ErrorCatcher/Tests/ErrorRenderer/JsonErrorRendererTest.php +++ b/src/Symfony/Component/ErrorCatcher/Tests/ErrorRenderer/JsonErrorRendererTest.php @@ -19,7 +19,7 @@ class JsonErrorRendererTest extends TestCase { public function testRender() { - $exception = FlattenException::create(new \RuntimeException('Foo')); + $exception = FlattenException::createFromThrowable(new \RuntimeException('Foo')); $expected = '{"title":"Internal Server Error","status":500,"detail":"Foo","exceptions":[{"message":"Foo","class":"RuntimeException","trace":'; $this->assertStringStartsWith($expected, (new JsonErrorRenderer())->render($exception)); diff --git a/src/Symfony/Component/ErrorCatcher/Tests/ErrorRenderer/TxtErrorRendererTest.php b/src/Symfony/Component/ErrorCatcher/Tests/ErrorRenderer/TxtErrorRendererTest.php index b3c817581ca19..8ee6ee3bf77de 100644 --- a/src/Symfony/Component/ErrorCatcher/Tests/ErrorRenderer/TxtErrorRendererTest.php +++ b/src/Symfony/Component/ErrorCatcher/Tests/ErrorRenderer/TxtErrorRendererTest.php @@ -19,7 +19,7 @@ class TxtErrorRendererTest extends TestCase { public function testRender() { - $exception = FlattenException::create(new \RuntimeException('Foo')); + $exception = FlattenException::createFromThrowable(new \RuntimeException('Foo')); $expected = '[title] Internal Server Error%A[status] 500%A[detail] Foo%A[1] RuntimeException: Foo%A'; $this->assertStringMatchesFormat($expected, (new TxtErrorRenderer())->render($exception)); diff --git a/src/Symfony/Component/ErrorCatcher/Tests/ErrorRenderer/XmlErrorRendererTest.php b/src/Symfony/Component/ErrorCatcher/Tests/ErrorRenderer/XmlErrorRendererTest.php index f98e43920ab22..dc2bf259956e1 100644 --- a/src/Symfony/Component/ErrorCatcher/Tests/ErrorRenderer/XmlErrorRendererTest.php +++ b/src/Symfony/Component/ErrorCatcher/Tests/ErrorRenderer/XmlErrorRendererTest.php @@ -19,7 +19,7 @@ class XmlErrorRendererTest extends TestCase { public function testRender() { - $exception = FlattenException::create(new \RuntimeException('Foo')); + $exception = FlattenException::createFromThrowable(new \RuntimeException('Foo')); $expected = '%A%AInternal Server Error%A500%AFoo%A'; $this->assertStringMatchesFormat($expected, (new XmlErrorRenderer())->render($exception)); diff --git a/src/Symfony/Component/ErrorCatcher/Tests/Exception/FlattenExceptionTest.php b/src/Symfony/Component/ErrorCatcher/Tests/Exception/FlattenExceptionTest.php index c6d99662d2893..3f8749578bd69 100644 --- a/src/Symfony/Component/ErrorCatcher/Tests/Exception/FlattenExceptionTest.php +++ b/src/Symfony/Component/ErrorCatcher/Tests/Exception/FlattenExceptionTest.php @@ -34,10 +34,10 @@ class FlattenExceptionTest extends TestCase { public function testStatusCode() { - $flattened = FlattenException::create(new \RuntimeException(), 403); + $flattened = FlattenException::createFromThrowable(new \RuntimeException(), 403); $this->assertEquals('403', $flattened->getStatusCode()); - $flattened = FlattenException::create(new \RuntimeException()); + $flattened = FlattenException::createFromThrowable(new \RuntimeException()); $this->assertEquals('500', $flattened->getStatusCode()); $flattened = FlattenException::createFromThrowable(new \DivisionByZeroError(), 403); @@ -46,72 +46,72 @@ public function testStatusCode() $flattened = FlattenException::createFromThrowable(new \DivisionByZeroError()); $this->assertEquals('500', $flattened->getStatusCode()); - $flattened = FlattenException::create(new NotFoundHttpException()); + $flattened = FlattenException::createFromThrowable(new NotFoundHttpException()); $this->assertEquals('404', $flattened->getStatusCode()); - $flattened = FlattenException::create(new UnauthorizedHttpException('Basic realm="My Realm"')); + $flattened = FlattenException::createFromThrowable(new UnauthorizedHttpException('Basic realm="My Realm"')); $this->assertEquals('401', $flattened->getStatusCode()); - $flattened = FlattenException::create(new BadRequestHttpException()); + $flattened = FlattenException::createFromThrowable(new BadRequestHttpException()); $this->assertEquals('400', $flattened->getStatusCode()); - $flattened = FlattenException::create(new NotAcceptableHttpException()); + $flattened = FlattenException::createFromThrowable(new NotAcceptableHttpException()); $this->assertEquals('406', $flattened->getStatusCode()); - $flattened = FlattenException::create(new ConflictHttpException()); + $flattened = FlattenException::createFromThrowable(new ConflictHttpException()); $this->assertEquals('409', $flattened->getStatusCode()); - $flattened = FlattenException::create(new MethodNotAllowedHttpException(['POST'])); + $flattened = FlattenException::createFromThrowable(new MethodNotAllowedHttpException(['POST'])); $this->assertEquals('405', $flattened->getStatusCode()); - $flattened = FlattenException::create(new AccessDeniedHttpException()); + $flattened = FlattenException::createFromThrowable(new AccessDeniedHttpException()); $this->assertEquals('403', $flattened->getStatusCode()); - $flattened = FlattenException::create(new GoneHttpException()); + $flattened = FlattenException::createFromThrowable(new GoneHttpException()); $this->assertEquals('410', $flattened->getStatusCode()); - $flattened = FlattenException::create(new LengthRequiredHttpException()); + $flattened = FlattenException::createFromThrowable(new LengthRequiredHttpException()); $this->assertEquals('411', $flattened->getStatusCode()); - $flattened = FlattenException::create(new PreconditionFailedHttpException()); + $flattened = FlattenException::createFromThrowable(new PreconditionFailedHttpException()); $this->assertEquals('412', $flattened->getStatusCode()); - $flattened = FlattenException::create(new PreconditionRequiredHttpException()); + $flattened = FlattenException::createFromThrowable(new PreconditionRequiredHttpException()); $this->assertEquals('428', $flattened->getStatusCode()); - $flattened = FlattenException::create(new ServiceUnavailableHttpException()); + $flattened = FlattenException::createFromThrowable(new ServiceUnavailableHttpException()); $this->assertEquals('503', $flattened->getStatusCode()); - $flattened = FlattenException::create(new TooManyRequestsHttpException()); + $flattened = FlattenException::createFromThrowable(new TooManyRequestsHttpException()); $this->assertEquals('429', $flattened->getStatusCode()); - $flattened = FlattenException::create(new UnsupportedMediaTypeHttpException()); + $flattened = FlattenException::createFromThrowable(new UnsupportedMediaTypeHttpException()); $this->assertEquals('415', $flattened->getStatusCode()); if (class_exists(SuspiciousOperationException::class)) { - $flattened = FlattenException::create(new SuspiciousOperationException()); + $flattened = FlattenException::createFromThrowable(new SuspiciousOperationException()); $this->assertEquals('400', $flattened->getStatusCode()); } } public function testHeadersForHttpException() { - $flattened = FlattenException::create(new MethodNotAllowedHttpException(['POST'])); + $flattened = FlattenException::createFromThrowable(new MethodNotAllowedHttpException(['POST'])); $this->assertEquals(['Allow' => 'POST'], $flattened->getHeaders()); - $flattened = FlattenException::create(new UnauthorizedHttpException('Basic realm="My Realm"')); + $flattened = FlattenException::createFromThrowable(new UnauthorizedHttpException('Basic realm="My Realm"')); $this->assertEquals(['WWW-Authenticate' => 'Basic realm="My Realm"'], $flattened->getHeaders()); - $flattened = FlattenException::create(new ServiceUnavailableHttpException('Fri, 31 Dec 1999 23:59:59 GMT')); + $flattened = FlattenException::createFromThrowable(new ServiceUnavailableHttpException('Fri, 31 Dec 1999 23:59:59 GMT')); $this->assertEquals(['Retry-After' => 'Fri, 31 Dec 1999 23:59:59 GMT'], $flattened->getHeaders()); - $flattened = FlattenException::create(new ServiceUnavailableHttpException(120)); + $flattened = FlattenException::createFromThrowable(new ServiceUnavailableHttpException(120)); $this->assertEquals(['Retry-After' => 120], $flattened->getHeaders()); - $flattened = FlattenException::create(new TooManyRequestsHttpException('Fri, 31 Dec 1999 23:59:59 GMT')); + $flattened = FlattenException::createFromThrowable(new TooManyRequestsHttpException('Fri, 31 Dec 1999 23:59:59 GMT')); $this->assertEquals(['Retry-After' => 'Fri, 31 Dec 1999 23:59:59 GMT'], $flattened->getHeaders()); - $flattened = FlattenException::create(new TooManyRequestsHttpException(120)); + $flattened = FlattenException::createFromThrowable(new TooManyRequestsHttpException(120)); $this->assertEquals(['Retry-After' => 120], $flattened->getHeaders()); } @@ -133,7 +133,7 @@ public function testFlattenHttpException(\Throwable $exception) public function testWrappedThrowable() { $exception = new FatalThrowableError(new \DivisionByZeroError('Ouch', 42)); - $flattened = FlattenException::create($exception); + $flattened = FlattenException::createFromThrowable($exception); $this->assertSame('Ouch', $flattened->getMessage(), 'The message is copied from the original error.'); $this->assertSame(42, $flattened->getCode(), 'The code is copied from the original error.'); @@ -169,7 +169,7 @@ public function testPreviousError() { $exception = new \Exception('test', 123, new \ParseError('Oh noes!', 42)); - $flattened = FlattenException::create($exception)->getPrevious(); + $flattened = FlattenException::createFromThrowable($exception)->getPrevious(); $this->assertEquals($flattened->getMessage(), 'Oh noes!', 'The message is copied from the original exception.'); $this->assertEquals($flattened->getCode(), 42, 'The code is copied from the original exception.'); @@ -223,7 +223,7 @@ public function testCreate() $this->assertSame( FlattenException::createFromThrowable($exception)->toArray(), - FlattenException::create($exception)->toArray() + FlattenException::createFromThrowable($exception)->toArray() ); } @@ -262,7 +262,7 @@ function () {}, NAN, ]); - $flattened = FlattenException::create($exception); + $flattened = FlattenException::createFromThrowable($exception); $trace = $flattened->getTrace(); $args = $trace[1]['args']; $array = $args[0][1]; @@ -303,7 +303,7 @@ public function testRecursionInArguments() $a = ['foo', [2, &$a]]; $exception = $this->createException($a); - $flattened = FlattenException::create($exception); + $flattened = FlattenException::createFromThrowable($exception); $trace = $flattened->getTrace(); $this->assertContains('*DEEP NESTED ARRAY*', serialize($trace)); } @@ -322,7 +322,7 @@ public function testTooBigArray() $a[21] = 'value1'; $exception = $this->createException($a); - $flattened = FlattenException::create($exception); + $flattened = FlattenException::createFromThrowable($exception); $trace = $flattened->getTrace(); $this->assertSame($trace[1]['args'][0], ['array', ['array', '*SKIPPED over 10000 entries*']]); @@ -335,12 +335,12 @@ public function testTooBigArray() public function testAnonymousClass() { - $flattened = FlattenException::create(new class() extends \RuntimeException { + $flattened = FlattenException::createFromThrowable(new class() extends \RuntimeException { }); $this->assertSame('RuntimeException@anonymous', $flattened->getClass()); - $flattened = FlattenException::create(new \Exception(sprintf('Class "%s" blah.', \get_class(new class() extends \RuntimeException { + $flattened = FlattenException::createFromThrowable(new \Exception(sprintf('Class "%s" blah.', \get_class(new class() extends \RuntimeException { })))); $this->assertSame('Class "RuntimeException@anonymous" blah.', $flattened->getMessage()); @@ -350,7 +350,7 @@ public function testToStringEmptyMessage() { $exception = new \RuntimeException(); - $flattened = FlattenException::create($exception); + $flattened = FlattenException::createFromThrowable($exception); $this->assertSame($exception->getTraceAsString(), $flattened->getTraceAsString()); $this->assertSame($exception->__toString(), $flattened->getAsString()); @@ -364,7 +364,7 @@ public function testToString() $exception = $test('foo123', 1, null, 1.5); - $flattened = FlattenException::create($exception); + $flattened = FlattenException::createFromThrowable($exception); $this->assertSame($exception->getTraceAsString(), $flattened->getTraceAsString()); $this->assertSame($exception->__toString(), $flattened->getAsString()); @@ -375,7 +375,7 @@ public function testToStringParent() $exception = new \LogicException('This is message 1'); $exception = new \RuntimeException('This is messsage 2', 500, $exception); - $flattened = FlattenException::create($exception); + $flattened = FlattenException::createFromThrowable($exception); $this->assertSame($exception->getTraceAsString(), $flattened->getTraceAsString()); $this->assertSame($exception->__toString(), $flattened->getAsString()); diff --git a/src/Symfony/Component/HttpKernel/DataCollector/ExceptionDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/ExceptionDataCollector.php index 9d715b91c138b..62c10a1347093 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/ExceptionDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/ExceptionDataCollector.php @@ -29,7 +29,7 @@ public function collect(Request $request, Response $response, \Exception $except { if (null !== $exception) { $this->data = [ - 'exception' => FlattenException::create($exception), + 'exception' => FlattenException::createFromThrowable($exception), ]; } } diff --git a/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php b/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php index 0d096252fbace..833a0e3b6b4f3 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php @@ -42,7 +42,7 @@ public function __construct($controller, LoggerInterface $logger = null, $debug public function logKernelException(GetResponseForExceptionEvent $event) { - $e = FlattenException::create($event->getException()); + $e = FlattenException::createFromThrowable($event->getException()); $this->logException($event->getException(), sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', $e->getClass(), $e->getMessage(), $e->getFile(), $e->getLine())); } @@ -64,7 +64,7 @@ public function onKernelException(GetResponseForExceptionEvent $event) try { $response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, false); } catch (\Exception $e) { - $f = FlattenException::create($e); + $f = FlattenException::createFromThrowable($e); $this->logException($e, sprintf('Exception thrown when handling an exception (%s: %s at %s line %s)', $f->getClass(), $f->getMessage(), $e->getFile(), $e->getLine())); @@ -132,7 +132,7 @@ protected function duplicateRequest(\Exception $exception, Request $request) { $attributes = [ '_controller' => $this->controller, - 'exception' => FlattenException::create($exception), + 'exception' => FlattenException::createFromThrowable($exception), 'logger' => $this->logger instanceof DebugLoggerInterface ? $this->logger : null, ]; $request = $request->duplicate(null, null, $attributes); diff --git a/src/Symfony/Component/HttpKernel/Tests/DataCollector/ExceptionDataCollectorTest.php b/src/Symfony/Component/HttpKernel/Tests/DataCollector/ExceptionDataCollectorTest.php index d7d45e1bdf5a1..08e0ebb2d4065 100644 --- a/src/Symfony/Component/HttpKernel/Tests/DataCollector/ExceptionDataCollectorTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/DataCollector/ExceptionDataCollectorTest.php @@ -23,7 +23,7 @@ public function testCollect() { $e = new \Exception('foo', 500); $c = new ExceptionDataCollector(); - $flattened = FlattenException::create($e); + $flattened = FlattenException::createFromThrowable($e); $trace = $flattened->getTrace(); $this->assertFalse($c->hasException()); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy