From c6619dd170fdfc242364bea8964e28ede1fd0c73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20L=C3=BCder?= Date: Tue, 20 Feb 2024 08:33:12 +0800 Subject: [PATCH 1/2] Restore default createResponse contentType to JSON --- Classes/Middleware/MiddlewareAbstract.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Classes/Middleware/MiddlewareAbstract.php b/Classes/Middleware/MiddlewareAbstract.php index d4524cc..a6f920d 100644 --- a/Classes/Middleware/MiddlewareAbstract.php +++ b/Classes/Middleware/MiddlewareAbstract.php @@ -74,6 +74,7 @@ public function createResponse(string $string, string $contentType = ContentType } switch ($contentType) { + case ContentTypeDefinition::DEFAULT: case ContentTypeDefinition::JSON: $response = $response->withHeader('Content-Type', 'application/json; charset=utf-8'); break; From a3b1a4c27ef723d59b2e8b616e1ce1689eaccd48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20L=C3=BCder?= Date: Tue, 20 Feb 2024 08:40:16 +0800 Subject: [PATCH 2/2] Added PHPdoc to explain what default will do. --- Classes/Middleware/MiddlewareAbstract.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Classes/Middleware/MiddlewareAbstract.php b/Classes/Middleware/MiddlewareAbstract.php index a6f920d..9bf16cc 100644 --- a/Classes/Middleware/MiddlewareAbstract.php +++ b/Classes/Middleware/MiddlewareAbstract.php @@ -5,12 +5,14 @@ namespace JAKOTA\Typo3ToolBox\Middleware; +use InvalidArgumentException; use JAKOTA\Typo3ToolBox\Definition\ContentTypeDefinition; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; +use RuntimeException; use TYPO3\CMS\Core\Http\Response; use TYPO3\CMS\Core\Information\Typo3Version; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -64,7 +66,10 @@ public function checkRequest(string $path, callable $callable, string $method): } } } - + /** + * + * @param string $contentType Defaults to JSON content type if omitted. + */ public function createResponse(string $string, string $contentType = ContentTypeDefinition::DEFAULT): ResponseInterface { $typo3Version = GeneralUtility::makeInstance(Typo3Version::class); if (version_compare($typo3Version->getVersion(), '10.1.0') >= 0) {