Files
kiri-core/http-message/Parse.php
T

35 lines
603 B
PHP
Raw Normal View History

2021-09-10 03:33:45 +08:00
<?php
2021-09-10 10:11:23 +08:00
namespace Protocol\Message;
2021-09-10 03:33:45 +08:00
use Kiri\Core\Xml;
class Parse
{
2021-09-10 10:24:11 +08:00
/**
* @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;
}
2021-09-10 03:33:45 +08:00
}