35 lines
595 B
PHP
35 lines
595 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($content);
|
|
}
|
|
if (str_contains($contentType, 'xml')) {
|
|
return Xml::toArray($content);
|
|
}
|
|
if (str_contains($contentType, 'x-www-form-urlencoded')) {
|
|
parse_str($content, $array);
|
|
return $array;
|
|
}
|
|
if (str_contains($contentType, 'serialize')) {
|
|
return unserialize($content);
|
|
}
|
|
return $content;
|
|
}
|
|
|
|
}
|