LazyAssertionException.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * Assert
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * If you did not receive a copy of the license and are unable to
  10. * obtain it through the world-wide-web, please send an email
  11. * to kontakt@beberlei.de so I can send you a copy immediately.
  12. */
  13. namespace Assert;
  14. class LazyAssertionException extends InvalidArgumentException
  15. {
  16. /**
  17. * @var InvalidArgumentException[]
  18. */
  19. private $errors = array();
  20. /**
  21. * @param InvalidArgumentException[] $errors
  22. *
  23. * @return self
  24. */
  25. public static function fromErrors(array $errors)
  26. {
  27. $message = \sprintf('The following %d assertions failed:', \count($errors)) . "\n";
  28. $i = 1;
  29. foreach ($errors as $error) {
  30. $message .= \sprintf("%d) %s: %s\n", $i++, $error->getPropertyPath(), $error->getMessage());
  31. }
  32. return new static($message, $errors);
  33. }
  34. public function __construct($message, array $errors)
  35. {
  36. parent::__construct($message, 0, null, null);
  37. $this->errors = $errors;
  38. }
  39. public function getErrorExceptions()
  40. {
  41. return $this->errors;
  42. }
  43. }