Skip to content

Commit 640ede4

Browse files
committed
deprecated FlattenException::create()
1 parent f28762f commit 640ede4

File tree

19 files changed

+69
-64
lines changed

19 files changed

+69
-64
lines changed

src/Symfony/Bundle/TwigBundle/Controller/PreviewErrorController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct(HttpKernelInterface $kernel, $controller)
3535

3636
public function previewErrorPageAction(Request $request, $code)
3737
{
38-
$exception = FlattenException::create(new \Exception('Something has intentionally gone wrong.'), $code);
38+
$exception = FlattenException::createFromThrowable(new \Exception('Something has intentionally gone wrong.'), $code);
3939

4040
/*
4141
* This Request mimics the parameters set by

src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function testShowActionCanBeForcedToShowErrorPage()
2626

2727
$request = $this->createRequest('html');
2828
$request->attributes->set('showException', false);
29-
$exception = FlattenException::create(new \Exception(), 404);
29+
$exception = FlattenException::createFromThrowable(new \Exception(), 404);
3030
$controller = new ExceptionController($twig, /* "showException" defaults to --> */ true);
3131

3232
$response = $controller->showAction($request, $exception, null);
@@ -40,7 +40,7 @@ public function testFallbackToHtmlIfNoTemplateForRequestedFormat()
4040
$twig = $this->createTwigEnv(['@Twig/Exception/error.html.twig' => '<html></html>']);
4141

4242
$request = $this->createRequest('txt');
43-
$exception = FlattenException::create(new \Exception());
43+
$exception = FlattenException::createFromThrowable(new \Exception());
4444
$controller = new ExceptionController($twig, false);
4545

4646
$controller->showAction($request, $exception);
@@ -54,7 +54,7 @@ public function testFallbackToHtmlWithFullExceptionIfNoTemplateForRequestedForma
5454

5555
$request = $this->createRequest('txt');
5656
$request->attributes->set('showException', true);
57-
$exception = FlattenException::create(new \Exception());
57+
$exception = FlattenException::createFromThrowable(new \Exception());
5858
$controller = new ExceptionController($twig, false);
5959

6060
$controller->showAction($request, $exception);
@@ -67,7 +67,7 @@ public function testResponseHasRequestedMimeType()
6767
$twig = $this->createTwigEnv(['@Twig/Exception/error.json.twig' => '{}']);
6868

6969
$request = $this->createRequest('json');
70-
$exception = FlattenException::create(new \Exception());
70+
$exception = FlattenException::createFromThrowable(new \Exception());
7171
$controller = new ExceptionController($twig, false);
7272

7373
$response = $controller->showAction($request, $exception);

src/Symfony/Bundle/WebProfilerBundle/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"require": {
1919
"php": "^7.1.3",
2020
"symfony/config": "^4.2|^5.0",
21+
"symfony/error-handler": "^4.4|^5.0",
2122
"symfony/http-kernel": "^4.4",
2223
"symfony/routing": "^3.4|^4.0|^5.0",
2324
"symfony/twig-bundle": "^4.2|^5.0",

src/Symfony/Component/Debug/Exception/FlattenException.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,13 @@
2020
*/
2121
class FlattenException extends BaseFlattenException
2222
{
23+
/**
24+
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Exception::createFromThrowable() instead.
25+
*/
26+
public static function create(\Exception $exception, $statusCode = null, array $headers = []): self
27+
{
28+
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Exception::createFromThrowable() instead.', __METHOD__), E_USER_DEPRECATED);
29+
30+
return parent::createFromThrowable($exception, $statusCode, $headers);
31+
}
2332
}

src/Symfony/Component/ErrorHandler/ErrorRenderer/ErrorRenderer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ public function render($exception, string $format = 'html'): string
6262
throw new ErrorRendererNotFoundException(sprintf('No error renderer found for format "%s".', $format));
6363
}
6464

65-
if ($exception instanceof \Exception) {
66-
$exception = FlattenException::create($exception);
65+
if ($exception instanceof \Throwable) {
66+
$exception = FlattenException::createFromThrowable($exception);
6767
}
6868

6969
return $this->renderers[$format]->render($exception);

src/Symfony/Component/ErrorHandler/ErrorRenderer/HtmlErrorRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public function getBody(FlattenException $exception)
150150
} catch (\Exception $e) {
151151
// something nasty happened and we cannot throw an exception anymore
152152
if ($this->debug) {
153-
$e = FlattenException::create($e);
153+
$e = FlattenException::createFromThrowable($e);
154154
$exceptionMessage = sprintf('Exception thrown when handling an exception (%s: %s)', $e->getClass(), $this->escapeHtml($e->getMessage()));
155155
} else {
156156
$exceptionMessage = 'Whoops, looks like something went wrong.';

src/Symfony/Component/ErrorHandler/Exception/FlattenException.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ class FlattenException
3636
private $file;
3737
private $line;
3838

39-
public static function create(\Exception $exception, $statusCode = null, array $headers = [])
40-
{
41-
return static::createFromThrowable($exception, $statusCode, $headers);
42-
}
43-
4439
public static function createFromThrowable(\Throwable $exception, ?int $statusCode = null, array $headers = []): self
4540
{
4641
$e = new static();

src/Symfony/Component/ErrorHandler/ExceptionHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ public function handle(\Exception $exception)
160160
*/
161161
public function sendPhpResponse($exception)
162162
{
163-
if ($exception instanceof \Exception) {
164-
$exception = FlattenException::create($exception);
163+
if ($exception instanceof \Throwable) {
164+
$exception = FlattenException::createFromThrowable($exception);
165165
}
166166

167167
if (!headers_sent()) {

src/Symfony/Component/ErrorHandler/Tests/DependencyInjection/ErrorRendererTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testInvalidErrorRenderer()
2727
$container = $this->getMockBuilder('Psr\Container\ContainerInterface')->getMock();
2828
$container->expects($this->once())->method('has')->with('foo')->willReturn(false);
2929

30-
$exception = FlattenException::create(new \Exception('Foo'));
30+
$exception = FlattenException::createFromThrowable(new \Exception('Foo'));
3131
(new ErrorRenderer($container))->render($exception, 'foo');
3232
}
3333

@@ -48,7 +48,7 @@ public function testCustomErrorRenderer()
4848

4949
$errorRenderer = new ErrorRenderer($container);
5050

51-
$exception = FlattenException::create(new \RuntimeException('Foo'));
51+
$exception = FlattenException::createFromThrowable(new \RuntimeException('Foo'));
5252
$this->assertSame('Foo', $errorRenderer->render($exception, 'foo'));
5353
}
5454
}

src/Symfony/Component/ErrorHandler/Tests/ErrorRenderer/ErrorRendererTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ErrorRendererTest extends TestCase
2424
*/
2525
public function testErrorRendererNotFound()
2626
{
27-
$exception = FlattenException::create(new \Exception('foo'));
27+
$exception = FlattenException::createFromThrowable(new \Exception('foo'));
2828
(new ErrorRenderer([]))->render($exception, 'foo');
2929
}
3030

@@ -34,7 +34,7 @@ public function testErrorRendererNotFound()
3434
*/
3535
public function testInvalidErrorRenderer()
3636
{
37-
$exception = FlattenException::create(new \Exception('foo'));
37+
$exception = FlattenException::createFromThrowable(new \Exception('foo'));
3838
(new ErrorRenderer([new \stdClass()]))->render($exception, 'foo');
3939
}
4040

@@ -43,7 +43,7 @@ public function testCustomErrorRenderer()
4343
$renderers = [new FooErrorRenderer()];
4444
$errorRenderer = new ErrorRenderer($renderers);
4545

46-
$exception = FlattenException::create(new \RuntimeException('Foo'));
46+
$exception = FlattenException::createFromThrowable(new \RuntimeException('Foo'));
4747
$this->assertSame('Foo', $errorRenderer->render($exception, 'foo'));
4848
}
4949
}

0 commit comments

Comments
 (0)
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