Skip to content

Commit a20fb8f

Browse files
committed
Request::getBody() WIP
1 parent b2a5951 commit a20fb8f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/Http/Request.php

+14
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,20 @@ public function getRawBody(): ?string
267267
}
268268

269269

270+
/**
271+
* Returns decoded content of HTTP request body.
272+
*/
273+
public function getBody(): mixed
274+
{
275+
$type = $this->getHeader('Content-Type');
276+
return match ($type) {
277+
'application/json' => json_decode($this->getRawBody()),
278+
'application/x-www-form-urlencoded' => $_POST,
279+
default => throw new \Exception("Unsupported content type: $type"),
280+
};
281+
}
282+
283+
270284
/**
271285
* Returns basic HTTP authentication credentials.
272286
* @return array{string, string}|null

0 commit comments

Comments
 (0)