Files
kiri-core/http-message/Parse.php
T
as2252258@163.com a61e663cf0 111
2021-09-10 03:33:45 +08:00

35 lines
726 B
PHP

<?php
namespace Protocol\Message;
use Kiri\Core\Xml;
class Parse
{
/**
* @param $content
* @param $contentType
* @return mixed
*/
public static function data($content, $contentType): mixed
{
if (str_contains($contentType, 'json')) {
return json_encode($contentType);
}
if (str_contains($contentType, 'xml')) {
return Xml::toArray($contentType);
}
if (str_contains($contentType, 'x-www-form-urlencoded')) {
parse_str($content, $array);
return $array;
}
if (str_contains($contentType, 'serialize')) {
return unserialize($content);
}
return $content;
}
}