ValidatorInterface.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. use Hyperf\Utils\Contracts\MessageBag;
  13. use Hyperf\Utils\Contracts\MessageProvider;
  14. interface ValidatorInterface extends MessageProvider
  15. {
  16. /**
  17. * Run the validator's rules against its data.
  18. */
  19. public function validate(): array;
  20. /**
  21. * Get the attributes and values that were validated.
  22. */
  23. public function validated(): array;
  24. /**
  25. * Determine if the data fails the validation rules.
  26. */
  27. public function fails(): bool;
  28. /**
  29. * Get the failed validation rules.
  30. */
  31. public function failed(): array;
  32. /**
  33. * Add conditions to a given field based on a Closure.
  34. *
  35. * @param array|string $attribute
  36. * @param array|string $rules
  37. * @return $this
  38. */
  39. public function sometimes($attribute, $rules, callable $callback);
  40. /**
  41. * Add an after validation callback.
  42. *
  43. * @param callable|string $callback
  44. * @return $this
  45. */
  46. public function after($callback);
  47. /**
  48. * Get all of the validation error messages.
  49. */
  50. public function errors(): MessageBag;
  51. }