ValidatorInterface.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. namespace Hyperf\Contract;
  12. interface ValidatorInterface extends MessageProvider
  13. {
  14. /**
  15. * Run the validator's rules against its data.
  16. */
  17. public function validate(): array;
  18. /**
  19. * Get the attributes and values that were validated.
  20. */
  21. public function validated(): array;
  22. /**
  23. * Determine if the data fails the validation rules.
  24. */
  25. public function fails(): bool;
  26. /**
  27. * Get the failed validation rules.
  28. */
  29. public function failed(): array;
  30. /**
  31. * Add conditions to a given field based on a Closure.
  32. *
  33. * @param array|string $attribute
  34. * @param array|string $rules
  35. * @return $this
  36. */
  37. public function sometimes($attribute, $rules, callable $callback);
  38. /**
  39. * Add an after validation callback.
  40. *
  41. * @param callable|string $callback
  42. * @return $this
  43. */
  44. public function after($callback);
  45. /**
  46. * Get all of the validation error messages.
  47. */
  48. public function errors(): MessageBag;
  49. }