| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | namespace Atk4\Data; |
| 6: | |
| 7: | class ValidationException extends Exception |
| 8: | { |
| 9: | |
| 10: | public array $errors; |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | public function __construct(array $errors, Model $model = null) |
| 18: | { |
| 19: | if (count($errors) === 0) { |
| 20: | throw new Exception('At least one error must be given'); |
| 21: | } |
| 22: | |
| 23: | $this->errors = $errors; |
| 24: | |
| 25: | if (count($errors) === 1) { |
| 26: | parent::__construct(reset($errors)); |
| 27: | |
| 28: | $this->addMoreInfo('field', array_key_first($errors)); |
| 29: | } else { |
| 30: | parent::__construct('Multiple validation errors'); |
| 31: | |
| 32: | $this->addMoreInfo('errors', $errors); |
| 33: | } |
| 34: | |
| 35: | $this->addMoreInfo('model', $model); |
| 36: | } |
| 37: | } |
| 38: | |