← All changes
|
app/Features/UserSettings/Exceptions/ValidationFailedExceptions.php
+33
-0
2.0.1
→
2.1.1
View file →
| @@ -1,0 +1,33 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +declare(strict_types=1); | |
| 4 | + | |
| 5 | +namespace Metricool\Features\UserSettings\Exceptions; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * Is thrown when a storing setting fails validation. It contains a list of all the | |
| 9 | + * validation errors | |
| 10 | + */ | |
| 11 | +class ValidationFailedExceptions extends \RuntimeException | |
| 12 | +{ | |
| 13 | + /** @var ValidatorFailedException[] */ | |
| 14 | + public array $validationErrors = []; | |
| 15 | + | |
| 16 | + public function __construct(array $validationErrors) | |
| 17 | + { | |
| 18 | + parent::__construct('The validation of the settings failed'); | |
| 19 | + | |
| 20 | + $this->validationErrors = $validationErrors; | |
| 21 | + } | |
| 22 | + | |
| 23 | + public function getErrors(): array | |
| 24 | + { | |
| 25 | + $errors = []; | |
| 26 | + foreach ($this->validationErrors as $fieldName => $error) { | |
| 27 | + $errors[$fieldName] = [ | |
| 28 | + 'message' => $error->getMessage() | |
| 29 | + ]; | |
| 30 | + } | |
| 31 | + return $errors; | |
| 32 | + } | |
| 33 | +} | |