OpenXE/classes/Modules/Resubmission/Exception/ValidationFailedException.php

38 lines
825 B
PHP
Raw Normal View History

2021-05-21 08:49:41 +02:00
<?php
namespace Xentral\Modules\Resubmission\Exception;
use RuntimeException;
final class ValidationFailedException extends RuntimeException implements ResubmissionExceptionInterface
{
/** @var array $errors */
private $errors = [];
/**
* @param array $errors
*
* @return self
*/
public static function fromErrors(array $errors)
{
$errorString = '';
foreach ($errors as $propertyName => $propertyErrors) {
$errorString .= implode("\r\n", $propertyErrors);
}
$exception = new self('Validation failed with following errors: ' . "\n\n" . $errorString);
$exception->errors = $errors;
return $exception;
}
/**
* @return array
*/
public function getErrors()
{
return $this->errors;
}
}