2017-06-25 00:49:09 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Exceptions\Model;
|
|
|
|
|
2022-10-14 16:59:20 +00:00
|
|
|
use Illuminate\Support\MessageBag;
|
2022-06-26 20:31:48 +00:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2017-06-25 00:49:09 +00:00
|
|
|
use Illuminate\Contracts\Validation\Validator;
|
2017-12-17 20:57:05 +00:00
|
|
|
use Pterodactyl\Exceptions\PterodactylException;
|
2017-06-25 00:49:09 +00:00
|
|
|
use Illuminate\Contracts\Support\MessageProvider;
|
2017-12-17 20:57:05 +00:00
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
|
2017-06-25 00:49:09 +00:00
|
|
|
|
2017-12-17 20:57:05 +00:00
|
|
|
class DataValidationException extends PterodactylException implements HttpExceptionInterface, MessageProvider
|
2017-06-25 00:49:09 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* DataValidationException constructor.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function __construct(protected Validator $validator, protected Model $model)
|
2017-06-25 00:49:09 +00:00
|
|
|
{
|
2022-06-26 20:31:48 +00:00
|
|
|
$message = sprintf(
|
|
|
|
'Could not save %s[%s]: failed to validate data: %s',
|
|
|
|
get_class($model),
|
|
|
|
$model->getKey(),
|
|
|
|
$validator->errors()->toJson()
|
2017-12-17 20:57:05 +00:00
|
|
|
);
|
|
|
|
|
2022-06-26 20:31:48 +00:00
|
|
|
parent::__construct($message);
|
2017-06-25 00:49:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-17 20:57:05 +00:00
|
|
|
* Return the validator message bag.
|
2017-06-25 00:49:09 +00:00
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function getMessageBag(): MessageBag
|
2017-06-25 00:49:09 +00:00
|
|
|
{
|
|
|
|
return $this->validator->errors();
|
|
|
|
}
|
2017-12-17 20:57:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the status code for this request.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function getStatusCode(): int
|
2017-12-17 20:57:05 +00:00
|
|
|
{
|
|
|
|
return 500;
|
|
|
|
}
|
|
|
|
|
2022-10-14 16:59:20 +00:00
|
|
|
public function getHeaders(): array
|
2017-12-17 20:57:05 +00:00
|
|
|
{
|
|
|
|
return [];
|
|
|
|
}
|
2022-06-26 20:31:48 +00:00
|
|
|
|
|
|
|
public function getValidator(): Validator
|
|
|
|
{
|
|
|
|
return $this->validator;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getModel(): Model
|
|
|
|
{
|
|
|
|
return $this->model;
|
|
|
|
}
|
2017-06-25 00:49:09 +00:00
|
|
|
}
|