TestValidator.php 730 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\Module\Game\Validators;
  3. use Inhere\Validate\Validation;
  4. use UCore\Validator;
  5. /**
  6. * TestValidator
  7. * Validator独立逻辑验证器,应区分与Validation的区别
  8. *
  9. */
  10. class TestValidator extends Validator
  11. {
  12. /**
  13. * 验证逻辑
  14. * @param mixed $value
  15. * @param array $data
  16. * @return bool
  17. */
  18. public function validate(mixed $value, array $data): bool
  19. {
  20. if ($value > 3) {
  21. // > 3
  22. return false;
  23. }
  24. if ($value < -10) {
  25. // < -10 增加一个错误消息
  26. return $this->addError("这是一个极小的数字,不允许的!");
  27. }
  28. // 验证成功返回True
  29. return true;
  30. }
  31. }