Skip to content

Commit

Permalink
Merge pull request #576 from swoft-cloud/fix-IsBoolRule
Browse files Browse the repository at this point in the history
fix IsBoolRule Type conversion bug
  • Loading branch information
JasonYHZ authored May 13, 2020
2 parents f563df5 + 5db6b2f commit 83cafdd
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/validator/src/Rule/IsBoolRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ public function validate(array $data, string $propertyName, $item, $default = nu
throw new ValidatorException($message);
}

$value = $data[$propertyName];
if ($value == 'true' || $value == 'false' || is_bool($value)) {
$data[$propertyName] = (bool)$value;
$value = filter_var($data[$propertyName], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);

if (is_bool($value)) {
$data[$propertyName] = $value;
return $data;
}

Expand Down

0 comments on commit 83cafdd

Please sign in to comment.