Files
panel/app/Exceptions/Model/DataValidationException.php
Shift 445b1965b7 Apply Laravel coding style
Shift automatically applies the Laravel coding style - which uses the PSR-12 coding style as a base with some minor additions.

You may customize the code style applied by configuring [Pint](https://laravel.com/docs/pint), [PHP CS Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer), or [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) for your project root.

For more information on customizing the code style applied by Shift, [watch this short video](https://laravelshift.com/videos/shift-code-style).
2023-04-28 06:50:51 +00:00

75 lines
1.6 KiB
PHP

<?php
namespace Convoy\Exceptions\Model;
use Convoy\Exceptions\ConvoyException;
use Illuminate\Contracts\Support\MessageProvider;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\MessageBag;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
class DataValidationException extends ConvoyException implements HttpExceptionInterface, MessageProvider
{
/**
* The validator instance.
*/
protected Validator $validator;
/**
* The underlying model instance that triggered this exception.
*/
protected Model $model;
/**
* DataValidationException constructor.
*/
public function __construct(Validator $validator, Model $model)
{
$message = sprintf(
'Could not save %s[%s]: failed to validate data: %s',
get_class($model),
$model->getKey(),
$validator->errors()->toJson()
);
parent::__construct($message);
$this->validator = $validator;
$this->model = $model;
}
/**
* Return the validator message bag.
*
* @return MessageBag
*/
public function getMessageBag()
{
return $this->validator->errors();
}
/**
* Return the status code for this request.
*/
public function getStatusCode(): int
{
return 500;
}
public function getHeaders(): array
{
return [];
}
public function getValidator(): Validator
{
return $this->validator;
}
public function getModel(): Model
{
return $this->model;
}
}