Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3e54cb7

Browse filesBrowse files
committed
Merge branch '4.4'
* 4.4: deprecated FlattenException::create() [ErrorHandler] made IDEs and static analysis tools happy
2 parents bef96ee + b92e4ed commit 3e54cb7
Copy full SHA for 3e54cb7

File tree

Expand file treeCollapse file tree

17 files changed

+69
-65
lines changed
Filter options
Expand file treeCollapse file tree

17 files changed

+69
-65
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/Controller/PreviewErrorController.php
+1-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php
+4-4Lines 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/Component/Debug/Exception/FlattenException.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Debug/Exception/FlattenException.php
+9Lines 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/ErrorCatcher/ErrorRenderer/ErrorRenderer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/ErrorCatcher/ErrorRenderer/ErrorRenderer.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function addRenderer(ErrorRendererInterface $renderer, string $format): s
4949
/**
5050
* Renders an Exception and returns the Response content.
5151
*
52-
* @param \Exception|FlattenException $exception An \Exception or FlattenException instance
52+
* @param \Throwable|FlattenException $exception A \Throwable or FlattenException instance
5353
* @param string $format The request format (html, json, xml, etc.)
5454
*
5555
* @return string The Response content as a string
@@ -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 FlattenException) {
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/ErrorCatcher/ErrorRenderer/HtmlErrorRenderer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/ErrorCatcher/ErrorRenderer/HtmlErrorRenderer.php
+1-1Lines 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/ErrorCatcher/Exception/FlattenException.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/ErrorCatcher/Exception/FlattenException.php
-5Lines 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/ErrorCatcher/ExceptionHandler.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/ErrorCatcher/ExceptionHandler.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,12 @@ public function handle(\Exception $exception)
156156
* This method uses plain PHP functions like header() and echo to output
157157
* the response.
158158
*
159-
* @param \Exception|FlattenException $exception An \Exception or FlattenException instance
159+
* @param \Throwable|FlattenException $exception A \Throwable or FlattenException instance
160160
*/
161161
public function sendPhpResponse($exception)
162162
{
163-
if (!$exception instanceof FlattenException) {
164-
$exception = FlattenException::create($exception);
163+
if ($exception instanceof \Throwable) {
164+
$exception = FlattenException::createFromThrowable($exception);
165165
}
166166

167167
if (!headers_sent()) {

‎src/Symfony/Component/ErrorCatcher/Tests/DependencyInjection/ErrorRendererTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/ErrorCatcher/Tests/DependencyInjection/ErrorRendererTest.php
+2-2Lines 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/ErrorCatcher/Tests/ErrorRenderer/ErrorRendererTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/ErrorCatcher/Tests/ErrorRenderer/ErrorRendererTest.php
+3-3Lines 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/ErrorCatcher/Tests/ErrorRenderer/HtmlErrorRendererTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/ErrorCatcher/Tests/ErrorRenderer/HtmlErrorRendererTest.php
+1-1Lines 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/ErrorCatcher/Tests/ErrorRenderer/JsonErrorRendererTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/ErrorCatcher/Tests/ErrorRenderer/JsonErrorRendererTest.php
+1-1Lines 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/ErrorCatcher/Tests/ErrorRenderer/TxtErrorRendererTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/ErrorCatcher/Tests/ErrorRenderer/TxtErrorRendererTest.php
+1-1Lines 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/ErrorCatcher/Tests/ErrorRenderer/XmlErrorRendererTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/ErrorCatcher/Tests/ErrorRenderer/XmlErrorRendererTest.php
+1-1Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.