Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Annotation/Mapping/Validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ class Validate
private $params = [];

/**
* @var string
* @var array
*/
private $type = ValidateType::BODY;
private $type = [ValidateType::GET, ValidateType::BODY];

/**
* @var string
Expand Down Expand Up @@ -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'];
Expand Down Expand Up @@ -124,9 +124,9 @@ public function getParams(): array
}

/**
* @return string
* @return array
*/
public function getType(): string
public function getType()
{
return $this->type;
}
Expand Down
11 changes: 9 additions & 2 deletions src/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down