ReverseValidator.php 557 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace UCore\Validator;
  3. use UCore\Validator;
  4. /**
  5. * 使用验证器 验证,反向
  6. *
  7. */
  8. class ReverseValidator extends Validator
  9. {
  10. use ValidationMessage;
  11. public function validate(mixed $value, array $data): bool
  12. {
  13. $vaClass = $this->args;
  14. $data = [
  15. $value
  16. ];
  17. /**
  18. * @var Validator $va
  19. */
  20. $va = new $vaClass($this->validation);
  21. $res = $va->validate($value, $data);
  22. if ($res) {
  23. return false;
  24. }
  25. return true;
  26. }
  27. }