src/ValidationException.php source

1 <?php
2
3 namespace mini;
4
5 use mini\Validator\ValidationError;
6
7 /**
8 * Exception thrown when validation fails
9 *
10 * Wraps a ValidationError and provides access to the error details.
11 */
12 class ValidationException extends \Exception
13 {
14 /**
15 * @param ValidationError $error The validation error
16 */
17 public function __construct(public readonly ValidationError $error)
18 {
19 parent::__construct((string) $error);
20 }
21
22 /**
23 * Get the validation error
24 */
25 public function getError(): ValidationError
26 {
27 return $this->error;
28 }
29
30 /**
31 * Get property errors as array (for backwards compatibility)
32 *
33 * @return array<string, ValidationError>
34 */
35 public function getPropertyErrors(): array
36 {
37 return $this->error->getPropertyErrors();
38 }
39 }