改名
This commit is contained in:
@@ -12,14 +12,14 @@ class Parse
|
|||||||
* @param $content
|
* @param $content
|
||||||
* @param $contentType
|
* @param $contentType
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function data($content, $contentType): mixed
|
public static function data($content, $contentType): mixed
|
||||||
{
|
{
|
||||||
var_dump($contentType, $content);
|
if (empty($content)) {
|
||||||
if (str_contains($contentType, 'json')) {
|
return null;
|
||||||
return json_encode($content,true);
|
|
||||||
}
|
}
|
||||||
if (str_contains($contentType, 'xml')) {
|
if (str_starts_with($content, '<') || str_contains($contentType, 'xml')) {
|
||||||
return Xml::toArray($content);
|
return Xml::toArray($content);
|
||||||
}
|
}
|
||||||
if (str_contains($contentType, 'x-www-form-urlencoded')) {
|
if (str_contains($contentType, 'x-www-form-urlencoded')) {
|
||||||
@@ -29,7 +29,7 @@ class Parse
|
|||||||
if (str_contains($contentType, 'serialize')) {
|
if (str_contains($contentType, 'serialize')) {
|
||||||
return unserialize($content);
|
return unserialize($content);
|
||||||
}
|
}
|
||||||
return $content;
|
return json_encode($content, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,10 +78,9 @@ class ServerRequest extends Request implements ServerRequestInterface
|
|||||||
->withMethod($request->getMethod())
|
->withMethod($request->getMethod())
|
||||||
->withParsedBody(function (StreamInterface $stream, ?array $posts) {
|
->withParsedBody(function (StreamInterface $stream, ?array $posts) {
|
||||||
try {
|
try {
|
||||||
$content = $stream->getContents();
|
$content = Parse::data($stream->getContents(), $this->getContentType());
|
||||||
var_dump($content, $posts);
|
|
||||||
if (!empty($content)) {
|
if (!empty($content)) {
|
||||||
return Parse::data($content, $this->getContentType());
|
return $content;
|
||||||
}
|
}
|
||||||
return $posts;
|
return $posts;
|
||||||
} catch (\Throwable $throwable) {
|
} catch (\Throwable $throwable) {
|
||||||
|
|||||||
Reference in New Issue
Block a user