-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathValidator.php
35 lines (28 loc) · 884 Bytes
/
Validator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
/*
* This file is part of fab2s/laravel-dt0.
* (c) Fabrice de Stefanis / https://github.com/fab2s/laravel-dt0
* This source file is licensed under the MIT license which you will
* find in the LICENSE file or at https://opensource.org/licenses/MIT
*/
namespace fab2s\Dt0\Laravel;
use fab2s\Dt0\Attribute\Rule;
use fab2s\Dt0\Validator\ValidatorInterface;
use Illuminate\Support\Facades\Validator as ValidatorFacade;
use Illuminate\Validation\ValidationException;
class Validator implements ValidatorInterface
{
protected array $rules = [];
/**
* @throws ValidationException
*/
public function validate(array $data): array
{
return ValidatorFacade::make($data, $this->rules)->validate();
}
public function addRule(string $name, Rule $rule): static
{
$this->rules[$name] = $rule->rule;
return $this;
}
}