Skip to content

Instantly share code, notes, and snippets.

@tperrelli
Created January 16, 2017 09:54
Show Gist options
  • Save tperrelli/6cfc6d5837bee23af3b1eae7e9764ddf to your computer and use it in GitHub Desktop.
Save tperrelli/6cfc6d5837bee23af3b1eae7e9764ddf to your computer and use it in GitHub Desktop.
PHP ValidatorException
<?php
namespace App\Units\Core\Validation;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Support\Jsonable;
use Illuminate\Support\MessageBag;
/**
* Class ValidatorException
* @package App\Core\Validation
*/
class ValidatorException extends \Exception implements Jsonable, Arrayable {
/**
* @var MessageBag
*/
protected $messageBag;
/**
* @param MessageBag $messageBag
*/
public function __construct(MessageBag $messageBag){
$this->messageBag = $messageBag;
}
/**
* @return MessageBag
*/
public function getMessageBag(){
return $this->messageBag;
}
/**
* Get the instance as an array.
*
* @return array
*/
public function toArray()
{
return [
'error' => 'validation_exception',
'error_description' => $this->getMessageBag()
];
}
/**
* Convert the object to its JSON representation.
*
* @param int $options
* @return string
*/
public function toJson($options = 0)
{
return json_encode($this->toArray(), $options);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment