Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Exceptions/Model/DataValidationException.php
10279 views
1
<?php
2
3
namespace Pterodactyl\Exceptions\Model;
4
5
use Illuminate\Support\MessageBag;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Contracts\Validation\Validator;
8
use Pterodactyl\Exceptions\PterodactylException;
9
use Illuminate\Contracts\Support\MessageProvider;
10
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
11
12
class DataValidationException extends PterodactylException implements HttpExceptionInterface, MessageProvider
13
{
14
/**
15
* DataValidationException constructor.
16
*/
17
public function __construct(protected Validator $validator, protected Model $model)
18
{
19
$message = sprintf(
20
'Could not save %s[%s]: failed to validate data: %s',
21
get_class($model),
22
$model->getKey(),
23
$validator->errors()->toJson()
24
);
25
26
parent::__construct($message);
27
}
28
29
/**
30
* Return the validator message bag.
31
*/
32
public function getMessageBag(): MessageBag
33
{
34
return $this->validator->errors();
35
}
36
37
/**
38
* Return the status code for this request.
39
*/
40
public function getStatusCode(): int
41
{
42
return 500;
43
}
44
45
public function getHeaders(): array
46
{
47
return [];
48
}
49
50
public function getValidator(): Validator
51
{
52
return $this->validator;
53
}
54
55
public function getModel(): Model
56
{
57
return $this->model;
58
}
59
}
60
61