Skip to content

Commit

Permalink
fix: parse json body correct
Browse files Browse the repository at this point in the history
  • Loading branch information
KrohnMi committed Oct 21, 2024
1 parent 0ebfba4 commit d25a70a
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions Classes/Middleware/MiddlewareActionAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ abstract class MiddlewareActionAbstract extends ApiAbstract {
*/
protected array $queryParams = [];

protected ServerRequestInterface $request;

/**
* @var array<mixed>|object
*/
protected $requestBody = [];

protected ServerRequestInterface $request;

protected ?Site $site;

protected ?SiteLanguage $siteLanguage;
Expand All @@ -60,9 +60,17 @@ public function __construct(ServerRequestInterface $request, $pathParams) {
$this->request = $request;
$this->pathParams = $pathParams;
$this->queryParams = $this->request->getQueryParams();
$this->requestBody = $this->request->getParsedBody() ?? [];
$this->site = $this->request->getAttribute('site');

$contentType = $this->request->getHeaderLine('Content-Type');
if (false !== stripos($contentType, 'application/json')) {
/** @var null|array $parsedBody */
$parsedBody = json_decode($this->request->getBody()->getContents(), true);

Check failure on line 68 in Classes/Middleware/MiddlewareActionAbstract.php

View workflow job for this annotation

GitHub Actions / phpstan

PHPDoc tag @var for variable $parsedBody has no value type specified in iterable type array.
$this->requestBody = null !== $parsedBody ? $parsedBody : [];
} else {
$this->requestBody = $this->request->getParsedBody() ?? [];
}

$langId = $this->queryParams['L'] ?? false;
if (false != $langId) {
$this->siteLanguage = $this->site?->getLanguageById(intval($langId));
Expand Down

0 comments on commit d25a70a

Please sign in to comment.