Skip to content

Commit 33c6fd4

Browse files
committed
Update HttpBodyTrait.php
1 parent 8143d7e commit 33c6fd4

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/Traits/HttpBodyTrait.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function getParsedBody(bool $reload = false)
6969
$type = $this->getHeader('Content-Type');
7070
$body = $this->getBody();
7171
try {
72-
if ('application/json' === $type) {
72+
if (false !== strpos($type, 'application/json')) {
7373
$this->parsedBody = json_decode($body);
7474
}
7575
} catch (\Exception $e) {
@@ -85,13 +85,14 @@ public function getParsedBody(bool $reload = false)
8585
/**
8686
* Получение тела с преобразованием json.
8787
* @return object|null
88+
* @param bool|null парсить ли json в массив
8889
* @throws HttpException
8990
*/
90-
public function getJsonParsedBody(): ?object
91+
public function getJsonParsedBody(bool $toArray = false): ?object
9192
{
9293
$body = $this->getBody();
9394
try {
94-
$decoded = json_decode($body);
95+
$decoded = json_decode($body, $toArray);
9596
return $decoded ?? null;
9697
} catch (\Exception $e) {
9798
throw new HttpException("Failed to parse json body: $body");

0 commit comments

Comments
 (0)