diff --git a/src/Annotation/Mapping/Validate.php b/src/Annotation/Mapping/Validate.php index 4541ff1..28c734f 100644 --- a/src/Annotation/Mapping/Validate.php +++ b/src/Annotation/Mapping/Validate.php @@ -44,9 +44,9 @@ class Validate private $params = []; /** - * @var string + * @var array */ - private $type = ValidateType::BODY; + private $type = [ValidateType::GET, ValidateType::BODY]; /** * @var string @@ -76,7 +76,7 @@ public function __construct(array $values) $this->params = $values['params']; } if (isset($values['type'])) { - $this->type = $values['type']; + $this->type = (array) $values['type']; } if (isset($values['message'])) { $this->message = $values['message']; @@ -124,9 +124,9 @@ public function getParams(): array } /** - * @return string + * @return array */ - public function getType(): string + public function getType() { return $this->type; } diff --git a/src/Validator.php b/src/Validator.php index 56211b7..f2e23cc 100644 --- a/src/Validator.php +++ b/src/Validator.php @@ -85,11 +85,12 @@ public function validate( * @param array $body * @param array $validates * @param array $query + * @param string $requestMethod * * @return array * @throws ValidatorException */ - public function validateRequest(array $body, array $validates, array $query = []): array + public function validateRequest(array $body, array $validates, array $query = [], string $requestMethod=''): array { foreach ($validates as $validateName => $validate) { $validator = ValidatorRegister::getValidator($validateName); @@ -106,9 +107,15 @@ public function validateRequest(array $body, array $validates, array $query = [] $params = $validate['params'] ?? []; $validateType = $validate['type']; + $isGetValidateType = false; + + //判断该validator是否支持GET方式 + if (in_array(ValidateType::GET, $validateType)) { + $isGetValidateType = true; + } // Get query params - if ($validateType == ValidateType::GET) { + if ($requestMethod == RequestMethod::GET && $isGetValidateType) { $query = $this->validateValidator($query, $type, $validateName, $params, $validator, $fields, $unfields); continue;