From 1f46750f8b51e3aaf989ea8950d1c0cd612c4748 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 24 Jan 2023 15:02:24 +0100 Subject: [PATCH 1/7] Update license years (last time) --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 5c7ba05..f37c76b 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2019-2023 Fabien Potencier +Copyright (c) 2019-present Fabien Potencier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 5dfc1e3586b9a85f87867106dd5ccd51c81a3c84 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Fri, 3 Feb 2023 14:52:28 +0100 Subject: [PATCH 2/7] [WebProfilerBundle] Fix some minor HTML issues --- Resources/views/error.html.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/views/error.html.php b/Resources/views/error.html.php index 5416d03..dcd30c2 100644 --- a/Resources/views/error.html.php +++ b/Resources/views/error.html.php @@ -1,5 +1,5 @@ - + From 51374a69f6b7e7ea7cacb89ac7f21034b6f7706f Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 4 Feb 2023 11:07:10 +0100 Subject: [PATCH 3/7] fix test --- Tests/ErrorRenderer/HtmlErrorRendererTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/ErrorRenderer/HtmlErrorRendererTest.php b/Tests/ErrorRenderer/HtmlErrorRendererTest.php index f292d0f..4769055 100644 --- a/Tests/ErrorRenderer/HtmlErrorRendererTest.php +++ b/Tests/ErrorRenderer/HtmlErrorRendererTest.php @@ -37,7 +37,7 @@ public function getRenderData(): iterable $expectedNonDebug = << - + %AAn Error Occurred: Internal Server Error %A

The server returned a "500 Internal Server Error".

%A HTML; From 1471b167aef71a03cf9dd8cd1615a5f5f3f4d182 Mon Sep 17 00:00:00 2001 From: Wouter de Jong Date: Sun, 12 Feb 2023 18:34:23 +0100 Subject: [PATCH 4/7] [ErrorHandler] Do not patch return statements in closures --- DebugClassLoader.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/DebugClassLoader.php b/DebugClassLoader.php index 746e8d4..2d82c31 100644 --- a/DebugClassLoader.php +++ b/DebugClassLoader.php @@ -1090,7 +1090,20 @@ private function fixReturnStatements(\ReflectionMethod $method, string $returnTy } $end = $method->isGenerator() ? $i : $method->getEndLine(); + $inClosure = false; + $braces = 0; for (; $i < $end; ++$i) { + if (!$inClosure) { + $inClosure = str_contains($code[$i], 'function ('); + } + + if ($inClosure) { + $braces += substr_count($code[$i], '{') - substr_count($code[$i], '}'); + $inClosure = $braces > 0; + + continue; + } + if ('void' === $returnType) { $fixedCode[$i] = str_replace(' return null;', ' return;', $code[$i]); } elseif ('mixed' === $returnType || '?' === $returnType[0]) { From 56a94aa8cb5a5fbc411551d8d014a296b5456549 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Wed, 14 Dec 2022 15:42:16 +0100 Subject: [PATCH 5/7] Migrate to `static` data providers using `rector/rector` --- Tests/DebugClassLoaderTest.php | 2 +- Tests/ErrorEnhancer/ClassNotFoundErrorEnhancerTest.php | 2 +- Tests/ErrorEnhancer/UndefinedFunctionErrorEnhancerTest.php | 2 +- Tests/ErrorEnhancer/UndefinedMethodErrorEnhancerTest.php | 2 +- Tests/ErrorHandlerTest.php | 4 ++-- Tests/ErrorRenderer/HtmlErrorRendererTest.php | 2 +- Tests/Exception/FlattenExceptionTest.php | 4 ++-- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Tests/DebugClassLoaderTest.php b/Tests/DebugClassLoaderTest.php index 83d7793..66409dd 100644 --- a/Tests/DebugClassLoaderTest.php +++ b/Tests/DebugClassLoaderTest.php @@ -141,7 +141,7 @@ class_exists('Test\\'.__NAMESPACE__.'\\'.$class, true); $this->assertSame($xError, $lastError); } - public function provideDeprecatedSuper(): array + public static function provideDeprecatedSuper(): array { return [ ['DeprecatedInterfaceClass', 'DeprecatedInterface', 'implements'], diff --git a/Tests/ErrorEnhancer/ClassNotFoundErrorEnhancerTest.php b/Tests/ErrorEnhancer/ClassNotFoundErrorEnhancerTest.php index 1ca2f16..72ee199 100644 --- a/Tests/ErrorEnhancer/ClassNotFoundErrorEnhancerTest.php +++ b/Tests/ErrorEnhancer/ClassNotFoundErrorEnhancerTest.php @@ -72,7 +72,7 @@ public function testEnhance(string $originalMessage, string $enhancedMessage, $a $this->assertSame($expectedLine, $error->getLine()); } - public function provideClassNotFoundData() + public static function provideClassNotFoundData() { $autoloader = new ComposerClassLoader(); $autoloader->add('Symfony\Component\ErrorHandler\Error\\', realpath(__DIR__.'/../../Error')); diff --git a/Tests/ErrorEnhancer/UndefinedFunctionErrorEnhancerTest.php b/Tests/ErrorEnhancer/UndefinedFunctionErrorEnhancerTest.php index fe7d537..547e333 100644 --- a/Tests/ErrorEnhancer/UndefinedFunctionErrorEnhancerTest.php +++ b/Tests/ErrorEnhancer/UndefinedFunctionErrorEnhancerTest.php @@ -34,7 +34,7 @@ public function testEnhance(string $originalMessage, string $enhancedMessage) $this->assertSame($expectedLine, $error->getLine()); } - public function provideUndefinedFunctionData() + public static function provideUndefinedFunctionData() { return [ [ diff --git a/Tests/ErrorEnhancer/UndefinedMethodErrorEnhancerTest.php b/Tests/ErrorEnhancer/UndefinedMethodErrorEnhancerTest.php index b31c6c2..f417200 100644 --- a/Tests/ErrorEnhancer/UndefinedMethodErrorEnhancerTest.php +++ b/Tests/ErrorEnhancer/UndefinedMethodErrorEnhancerTest.php @@ -33,7 +33,7 @@ public function testEnhance(string $originalMessage, string $enhancedMessage) $this->assertSame($expectedLine, $error->getLine()); } - public function provideUndefinedMethodData() + public static function provideUndefinedMethodData() { return [ [ diff --git a/Tests/ErrorHandlerTest.php b/Tests/ErrorHandlerTest.php index 9688579..8f57bb5 100644 --- a/Tests/ErrorHandlerTest.php +++ b/Tests/ErrorHandlerTest.php @@ -448,7 +448,7 @@ public function testHandleException(string $expectedMessage, \Throwable $excepti } } - public function handleExceptionProvider(): array + public static function handleExceptionProvider(): array { return [ ['Uncaught Exception: foo', new \Exception('foo')], @@ -648,7 +648,7 @@ public function testErrorHandlerWhenLogging(bool $previousHandlerWasDefined, boo } } - public function errorHandlerWhenLoggingProvider(): iterable + public static function errorHandlerWhenLoggingProvider(): iterable { foreach ([false, true] as $previousHandlerWasDefined) { foreach ([false, true] as $loggerSetsAnotherHandler) { diff --git a/Tests/ErrorRenderer/HtmlErrorRendererTest.php b/Tests/ErrorRenderer/HtmlErrorRendererTest.php index 4769055..6680b95 100644 --- a/Tests/ErrorRenderer/HtmlErrorRendererTest.php +++ b/Tests/ErrorRenderer/HtmlErrorRendererTest.php @@ -24,7 +24,7 @@ public function testRender(\Throwable $exception, HtmlErrorRenderer $errorRender $this->assertStringMatchesFormat($expected, $errorRenderer->render($exception)->getAsString()); } - public function getRenderData(): iterable + public static function getRenderData(): iterable { $expectedDebug = << diff --git a/Tests/Exception/FlattenExceptionTest.php b/Tests/Exception/FlattenExceptionTest.php index da4fba3..6262656 100644 --- a/Tests/Exception/FlattenExceptionTest.php +++ b/Tests/Exception/FlattenExceptionTest.php @@ -226,7 +226,7 @@ public function testCreate() ); } - public function flattenDataProvider(): array + public static function flattenDataProvider(): array { return [ [new \Exception('test', 123), 'Exception'], @@ -234,7 +234,7 @@ public function flattenDataProvider(): array ]; } - public function stringAndIntDataProvider(): array + public static function stringAndIntDataProvider(): array { return [ [new \Exception('test1', 123)], From 016f1737cfade4714067dacc67911ded827f8494 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 6 Apr 2023 11:38:09 +0200 Subject: [PATCH 6/7] [ErrorHandler] Fix sending Vary header with SerializerErrorRenderer --- ErrorRenderer/SerializerErrorRenderer.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/ErrorRenderer/SerializerErrorRenderer.php b/ErrorRenderer/SerializerErrorRenderer.php index cec8e4d..4d1e752 100644 --- a/ErrorRenderer/SerializerErrorRenderer.php +++ b/ErrorRenderer/SerializerErrorRenderer.php @@ -55,7 +55,7 @@ public function __construct(SerializerInterface $serializer, $format, ErrorRende */ public function render(\Throwable $exception): FlattenException { - $headers = []; + $headers = ['Vary' => 'Accept']; $debug = \is_bool($this->debug) ? $this->debug : ($this->debug)($exception); if ($debug) { $headers['X-Debug-Exception'] = rawurlencode($exception->getMessage()); @@ -66,19 +66,17 @@ public function render(\Throwable $exception): FlattenException try { $format = \is_string($this->format) ? $this->format : ($this->format)($flattenException); - $headers = [ - 'Content-Type' => Request::getMimeTypes($format)[0] ?? $format, - 'Vary' => 'Accept', - ]; + $headers['Content-Type'] = Request::getMimeTypes($format)[0] ?? $format; - return $flattenException->setAsString($this->serializer->serialize($flattenException, $format, [ + $flattenException->setAsString($this->serializer->serialize($flattenException, $format, [ 'exception' => $exception, 'debug' => $debug, - ])) - ->setHeaders($flattenException->getHeaders() + $headers); + ])); } catch (NotEncodableValueException $e) { - return $this->fallbackErrorRenderer->render($exception); + $flattenException = $this->fallbackErrorRenderer->render($exception); } + + return $flattenException->setHeaders($flattenException->getHeaders() + $headers); } public static function getPreferredFormat(RequestStack $requestStack): \Closure From 218206b4772d9f412d7d277980c020d06e9d8a4e Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 17 Apr 2023 12:03:12 +0200 Subject: [PATCH 7/7] [ErrorHandler] Don't throw deprecations for HttplugClient --- DebugClassLoader.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/DebugClassLoader.php b/DebugClassLoader.php index 2d82c31..e19223d 100644 --- a/DebugClassLoader.php +++ b/DebugClassLoader.php @@ -21,6 +21,7 @@ use Prophecy\Prophecy\ProphecySubjectInterface; use ProxyManager\Proxy\ProxyInterface; use Symfony\Component\ErrorHandler\Internal\TentativeTypes; +use Symfony\Component\HttpClient\HttplugClient; /** * Autoloader checking if the class is really defined in the file found. @@ -414,7 +415,9 @@ public function checkAnnotations(\ReflectionClass $refl, string $class): array if (!isset(self::$checkedClasses[$use])) { $this->checkClass($use); } - if (isset(self::$deprecated[$use]) && strncmp($vendor, str_replace('_', '\\', $use), $vendorLen) && !isset(self::$deprecated[$class])) { + if (isset(self::$deprecated[$use]) && strncmp($vendor, str_replace('_', '\\', $use), $vendorLen) && !isset(self::$deprecated[$class]) + && !(HttplugClient::class === $class && \in_array($use, [\Http\Message\RequestFactory::class, \Http\Message\StreamFactory::class, \Http\Message\UriFactory::class], true)) + ) { $type = class_exists($class, false) ? 'class' : (interface_exists($class, false) ? 'interface' : 'trait'); $verb = class_exists($use, false) || interface_exists($class, false) ? 'extends' : (interface_exists($use, false) ? 'implements' : 'uses');