PageRequest.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php declare(strict_types=1);
  2. /**
  3. * Created by PhpStorm.
  4. * User: Inhere
  5. * Date: 2016/2/19 0019
  6. * Time: 23:35
  7. */
  8. namespace Inhere\ValidateTest\Example;
  9. use Inhere\Validate\Validation;
  10. /**
  11. * Class PageRequest
  12. */
  13. class PageRequest extends Validation
  14. {
  15. public function rules(): array
  16. {
  17. return [
  18. ['tagId,userId,freeTime', 'required'],
  19. ['tagId', 'size', 'min' => 4, 'max' => 567], // 4<= tagId <=567
  20. ['title', 'min', 'min' => 40],
  21. ['freeTime', 'number', 'msg' => '{attr} is require number!'],
  22. [
  23. 'test',
  24. 'number',
  25. 'when' => function ($data) {
  26. return isset($data['status']) && $data['status'] > 2;
  27. }
  28. ],
  29. ['userId', 'number', 'on' => 'other'],
  30. // ['userId', function($value){ return false;}],
  31. ];
  32. }
  33. public function translates(): array
  34. {
  35. return [
  36. 'userId' => '用户Id',
  37. ];
  38. }
  39. /**
  40. * custom validator message
  41. *
  42. * @return array
  43. */
  44. public function messages(): array
  45. {
  46. return [
  47. 'required' => '{attr} 是必填项。',
  48. ];
  49. }
  50. }