datatable.directory codebase https://datatable.directory/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
datatable.directory/porklib/Exceptions/SimpleValidationException.php

47 lines
1.0 KiB

<?php
namespace MightyPork\Exceptions;
use Illuminate\Contracts\Support\MessageProvider;
use Illuminate\Support\MessageBag;
class SimpleValidationException extends RuntimeException implements MessageProvider
{
/** @var MessageBag */
private $mb;
/**
* FBValidationException constructor.
*
* @param string|MessageProvider $key
* @param string $message
*/
public function __construct($key, $message = null)
{
if (is_null($message)) {
$this->mb = $key->getMessageBag();
} else {
$mb = new MessageBag();
$mb->add($key, $message);
$this->mb = $mb;
}
$str = '';
foreach ($this->mb->getMessages() as $key => $errors) {
$str .= $key . ': ' . implode(', ', $errors) . "\n";
}
parent::__construct($str);
}
/**
* Get the messages for the instance.
*
* @return MessageBag
*/
public function getMessageBag()
{
return $this->mb;
}
}