ValidationResult.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Validation;
  7. /**
  8. * ValidationResult object supposed to be created by dedicated validator service which makes a validation and checks
  9. * whether all entity invariants (business rules that always should be fulfilled) are valid.
  10. *
  11. * ValidationResult represents a container storing all the validation errors that happened during the entity validation.
  12. *
  13. * @api
  14. * @since 101.0.7
  15. */
  16. class ValidationResult
  17. {
  18. /**
  19. * @var array
  20. */
  21. private $errors = [];
  22. /**
  23. * @param array $errors
  24. */
  25. public function __construct(array $errors)
  26. {
  27. $this->errors = $errors;
  28. }
  29. /**
  30. * @return bool
  31. * @since 101.0.7
  32. */
  33. public function isValid(): bool
  34. {
  35. return empty($this->errors);
  36. }
  37. /**
  38. * @return array
  39. * @since 101.0.7
  40. */
  41. public function getErrors(): array
  42. {
  43. return $this->errors;
  44. }
  45. }