From c3617e89d55375f39b4183fb1b586aa1ec37868d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 6 Apr 2021 18:54:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HttpServer/Http/HttpParams.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/HttpServer/Http/HttpParams.php b/HttpServer/Http/HttpParams.php index 48c596b0..2cc70746 100644 --- a/HttpServer/Http/HttpParams.php +++ b/HttpServer/Http/HttpParams.php @@ -423,6 +423,27 @@ class HttpParams return $value; } + /** + * @param string $name + * @param string|null $default + * + * @return string|null + * @throws RequestException + */ + public function date(string $name, string $default = NULL): string|null + { + $value = $this->required($name, false); + if ($value === null) { + return $default; + } + $match = '/^\d{4}.*?([1-12]).*([1-31])$/'; + $match = preg_match($match, $value, $result); + if (!$match || $result[0] != $value) { + throw new RequestException('The request param :attribute format error', 4001); + } + return $value; + } + /** * @param string $name