Skip to content

Commit

Permalink
Merge pull request #7 from KrohnMi/fix-response-v.9
Browse files Browse the repository at this point in the history
Fix responseFactory not exist before 10.1
  • Loading branch information
tlueder authored Aug 26, 2022
2 parents 03197b2 + 59b1d93 commit fa551b0
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Classes/Middleware/MiddlewareAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use TYPO3\CMS\Core\Http\Response;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Utility\GeneralUtility;

abstract class MiddlewareAbstract implements MiddlewareInterface {
/**
Expand Down Expand Up @@ -58,7 +61,13 @@ public function checkRequest(string $path, callable $callable, string $method):
}

public function createResponse(string $string, bool $jsonOutput = true): ResponseInterface {
$response = $this->responseFactory->createResponse();
$typo3Version = GeneralUtility::makeInstance(Typo3Version::class);
if (version_compare($typo3Version->getVersion(), '10.1.0') >= 0) {
$response = $this->responseFactory->createResponse();
} else {
$response = new Response();
}

if ($jsonOutput) {
$response = $response->withHeader('Content-Type', 'application/json; charset=utf-8');
}
Expand Down

0 comments on commit fa551b0

Please sign in to comment.