This commit is contained in:
2021-08-05 19:14:08 +08:00
parent f7ec2b6b98
commit 7f9ae9556b
9 changed files with 175 additions and 43 deletions
+44 -4
View File
@@ -11,7 +11,6 @@ namespace HttpServer\Http;
use Exception;
use HttpServer\Exception\RequestException;
use JetBrains\PhpStorm\Pure;
use ReflectionException;
use Snowflake\Core\Json;
use Snowflake\Core\Xml;
@@ -36,6 +35,47 @@ class HttpParams
/** @var array|null */
private ?array $_files = [];
private mixed $_rawContent = '';
/**
* @param array|null $gets
*/
public function setGets(?array $gets): void
{
$this->_gets = $gets;
}
/**
* @param mixed $posts
*/
public function setPosts(mixed $posts): void
{
$this->_posts = $posts;
}
/**
* @param array|null $files
*/
public function setFiles(?array $files): void
{
$this->_files = $files;
}
/**
* @param mixed|string $rawContent
*/
public function setRawContent(mixed $rawContent, string $context_type): void
{
if (str_contains($context_type, 'json')) {
$this->_rawContent = json_decode($rawContent, true);
} else if (str_contains($context_type, 'xml')) {
$this->_rawContent = Xml::toArray($rawContent);
} else {
$this->_rawContent = $rawContent;
}
}
/**
* @return mixed
* @throws Exception
@@ -414,10 +454,10 @@ class HttpParams
*/
private function __files__($name = null): mixed
{
/** @var \Swoole\Http\Request $content */
$content = Context::getContext(\Swoole\Http\Request::class);
/** @var Request $content */
$content = Context::getContext(Request::class);
if (!empty($name)) {
return $content->files[$name] ?? null;
return $content->_f[$name] ?? null;
}
return $content->files ?? [];
}