File: /var/www/heifetz/heifetz-app/exceptions/Model/ModelValidationException.php
<?php
declare(strict_types=1);
namespace Exceptions\Model;
use Exception;
use Throwable;
class ModelValidationException extends Exception
{
private array $errors = [];
private function generateMessage(?array $errors): string
{
$errors ??= $this->errors ?? [];
return join(PHP_EOL, $errors);
}
public function getErrors(): array
{
return $this->errors;
}
public function __construct(array $errors, int $code = 0, ?Throwable $previous = null)
{
$this->errors = $errors;
parent::__construct($this->generateMessage($errors), $code, $previous);
}
}