This commit is contained in:
2021-10-25 18:25:14 +08:00
parent 6605aae410
commit a9d106a1cf
48 changed files with 5090 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
<?php
namespace Http\Message;
use Kiri\Core\Xml;
class Parse
{
/**
* @param $content
* @return mixed
* @throws \Exception
*/
public static function data($content): mixed
{
if (empty($content)) {
return null;
}
if (is_bool($content) || is_numeric($content)) {
return $content;
}
$start = substr($content, 0, 1);
return match ($start) {
'<' => Xml::toArray($content),
'[', '{' => json_decode($content, true),
default => call_user_func(function () use ($content) {
parse_str($content, $array);
return $array;
})
};
}
}