This commit is contained in:
2021-07-09 15:02:08 +08:00
parent 73cb94f657
commit ec37380175
+15 -12
View File
@@ -13,7 +13,6 @@ use Exception;
use HttpServer\Exception\RequestException; use HttpServer\Exception\RequestException;
use JetBrains\PhpStorm\Pure; use JetBrains\PhpStorm\Pure;
use ReflectionException; use ReflectionException;
use Snowflake\Core\Help;
use Snowflake\Core\Json; use Snowflake\Core\Json;
use Snowflake\Exception\NotFindClassException; use Snowflake\Exception\NotFindClassException;
use Snowflake\Snowflake; use Snowflake\Snowflake;
@@ -36,12 +35,12 @@ class HttpParams
/** /**
* HttpParams constructor. * HttpParams constructor.
* @param $body * @param mixed $body
* @param $get * @param array|null $get
* @param $files * @param array|null $files
* @param array $socket * @param array $socket
*/ */
public function __construct(mixed $body, ?array $get, ?array $files, $socket = []) public function __construct(mixed $body, ?array $get, ?array $files, array $socket = [])
{ {
$this->gets = $get ?? []; $this->gets = $get ?? [];
$this->files = $files ?? []; $this->files = $files ?? [];
@@ -216,7 +215,7 @@ class HttpParams
* @param array $defaultValue * @param array $defaultValue
* @return mixed * @return mixed
*/ */
public function array($name, $defaultValue = []): mixed public function array($name, array $defaultValue = []): mixed
{ {
return $this->body[$name] ?? $defaultValue; return $this->body[$name] ?? $defaultValue;
} }
@@ -238,7 +237,7 @@ class HttpParams
} }
/** /**
* @param $name * @param string $name
* @param bool $isNeed * @param bool $isNeed
* @return mixed * @return mixed
* @throws RequestException * @throws RequestException
@@ -278,13 +277,13 @@ class HttpParams
} }
/** /**
* @param $name * @param string $name
* @param bool $isNeed * @param bool $isNeed
* @param int $round * @param int $round
* @return float|null * @return float|null
* @throws RequestException * @throws RequestException
*/ */
public function float(string $name, bool $isNeed = FALSE, $round = 0): ?float public function float(string $name, bool $isNeed = FALSE, int $round = 0): ?float
{ {
$int = $this->required($name, $isNeed); $int = $this->required($name, $isNeed);
if ($int === null) { if ($int === null) {
@@ -312,9 +311,13 @@ class HttpParams
return $string; return $string;
} }
if (is_numeric($length)) { if (is_numeric($length)) {
$length = [$length, $length]; if ($length !== mb_strlen((string)$string)) {
throw new RequestException("The minimum value cannot be lower than $length, has length $length");
}
return $string;
} else {
return $this->between($string, $length[0], $length[1] ?? $length[0]);
} }
return $this->between($string, $length[0], $length[1] ?? $length[0]);
} }
/** /**
@@ -337,7 +340,7 @@ class HttpParams
} }
/** /**
* @param $name * @param string $name
* @param bool $isNeed * @param bool $isNeed
* *
* @return string|null * @return string|null