8000 deprecated FlattenException::create() · symfony/symfony@7ccb30b · GitHub
[go: up one dir, main page]

Skip to content

Commit 7ccb30b

Browse files
committed
deprecated FlattenException::create()
1 parent f28762f commit 7ccb30b

File tree

17 files changed

+67
-63
lines changed

17 files changed

+67
-63
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(FromThrowable(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/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
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class HtmlErrorRendererTest extends TestCase
1919
{
2020
public function testRender()
2121
{
22-
$exception = FlattenException::create(new \RuntimeException('Foo'));
22+
$exception = FlattenException::createFromThrowable(new \RuntimeException('Foo'));
2323
$expected = '<!DOCTYPE html>%A<html>%A<head>%A<title>Internal Server Error</title>%A<h1 class="break-long-words exception-message">Foo</h1>%A<abbr title="RuntimeException">RuntimeException</abbr>%A';
2424

2525
$this->assertStringMatchesFormat($expected, (new HtmlErrorRenderer())->render($exception));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class JsonErrorRendererTest extends TestCase
1919
{
2020
public function testRender()
2121
{
22-
$exception = FlattenException::create(new \RuntimeException('Foo'));
22+
$exception = FlattenException::createFromThrowable(new \RuntimeException('Foo'));
2323
$expected = '{"title":"Internal Server Error","status":500,"detail":"Foo","exceptions":[{"message":"Foo","class":"RuntimeException","trace":';
2424

2525
$this->assertStringStartsWith($expected, (new JsonErrorRenderer())->render($exception));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class TxtErrorRendererTest extends TestCase
1919
{
2020
public function testRender()
2121
{
22-
$exception = FlattenException::create(new \RuntimeException('Foo'));
22+
$exception = FlattenException::createFromThrowable(new \RuntimeException('Foo'));
2323
$expected = '[title] Internal Server Error%A[status] 500%A[detail] Foo%A[1] RuntimeException: Foo%A';
2424

2525
$this->assertStringMatchesFormat($expected, (new TxtErrorRenderer())->render($exception));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class XmlErrorRendererTest extends TestCase
1919
{
2020
public function testRender()
2121
{
22-
$exception = FlattenException::create(new \RuntimeException('Foo'));
22+
$exception = FlattenException::createFromThrowable(new \RuntimeException('Foo'));
2323
$expected = '<?xml version="1.0" encoding="UTF-8" ?>%A<problem xmlns="urn:ietf:rfc:7807">%A<title>Internal Server Error</title>%A<status>500</status>%A<detail>Foo</detail>%A';
2424

2525
$this->assertStringMatchesFormat($expected, (new XmlErrorRenderer())->render($exception));

0 commit comments

Comments
 (0)
0