This commit is contained in:
root
2025-11-13 19:52:28 +03:00
parent 8aeeb05b7d
commit 807dec3b6c
4646 changed files with 163445 additions and 626017 deletions

View File

@@ -58,7 +58,7 @@ class HttpRequest extends Request
* @param array $files _FILES
* @param array $cookies _COOKIE
*/
public function __construct(Server $server, array $queryString, array $postData, array $files, array $cookies)
public function __construct(Server $server, array $queryString, array $postData, array $files, array $cookies, array $jsonData = [])
{
$request = array_merge($queryString, $postData);
parent::__construct($server, $request);
@@ -69,7 +69,7 @@ class HttpRequest extends Request
$this->cookiesRaw = new Type\ParameterDictionary($cookies);
$this->cookies = new Type\ParameterDictionary($this->prepareCookie($cookies));
$this->headers = $this->buildHttpHeaders($server);
$this->jsonData = new Type\ParameterDictionary();
$this->jsonData = new Type\ParameterDictionary($jsonData);
}
private function buildHttpHeaders(Server $server)
@@ -594,4 +594,22 @@ class HttpRequest extends Request
}
}
}
public function decodeJsonStrict(): void
{
if (!$this->isJson())
{
throw new SystemException('Input is not valid JSON');
}
if (empty($this->jsonData->getValues()))
{
$json = Web\Json::decode(static::getInput());
if (!is_array($json))
{
throw new SystemException('Decoded JSON is not an array');
}
$this->jsonData = new Type\ParameterDictionary($json);
}
}
}