This commit is contained in:
2021-09-10 14:06:38 +08:00
parent 4feecd49f4
commit af88f79f02
2 changed files with 7 additions and 8 deletions
+5 -5
View File
@@ -12,14 +12,14 @@ class Parse
* @param $content
* @param $contentType
* @return mixed
* @throws \Exception
*/
public static function data($content, $contentType): mixed
{
var_dump($contentType, $content);
if (str_contains($contentType, 'json')) {
return json_encode($content,true);
if (empty($content)) {
return null;
}
if (str_contains($contentType, 'xml')) {
if (str_starts_with($content, '<') || str_contains($contentType, 'xml')) {
return Xml::toArray($content);
}
if (str_contains($contentType, 'x-www-form-urlencoded')) {
@@ -29,7 +29,7 @@ class Parse
if (str_contains($contentType, 'serialize')) {
return unserialize($content);
}
return $content;
return json_encode($content, true);
}
}
+2 -3
View File
@@ -78,10 +78,9 @@ class ServerRequest extends Request implements ServerRequestInterface
->withMethod($request->getMethod())
->withParsedBody(function (StreamInterface $stream, ?array $posts) {
try {
$content = $stream->getContents();
var_dump($content, $posts);
$content = Parse::data($stream->getContents(), $this->getContentType());
if (!empty($content)) {
return Parse::data($content, $this->getContentType());
return $content;
}
return $posts;
} catch (\Throwable $throwable) {