-
Notifications
You must be signed in to change notification settings - Fork 0
/
Validator.php
123 lines (108 loc) · 2.25 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
namespace Orchestra\Support;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Contracts\Validation\Factory;
use Illuminate\Contracts\Validation\Validator as ValidatorContract;
use Illuminate\Http\Request;
abstract class Validator
{
use Concerns\Validation;
/**
* List of rules.
*
* @var array
*/
protected $rules = [];
/**
* List of events.
*
* @var array
*/
protected $events = [];
/**
* List of local events.
*
* @var array
*/
protected $localEvents = [];
/**
* List of phrases.
*
* @var array
*/
protected $phrases = [];
/**
* Set state.
*
* @param string $scenario
* @param array $parameters
*
* @return $this
*/
public function state(string $scenario, array $parameters = [])
{
return $this->onValidationScenario($scenario, $parameters);
}
/**
* Add bindings.
*
* @param array $bindings
*
* @return $this
*/
public function bind(array $bindings)
{
return $this->bindToValidation($bindings);
}
/**
* Listen to events.
*
* @param string|array $events
*
* @return $this
*/
public function listen($events)
{
$this->localEvents = \array_merge($this->localEvents, Arr::wrap($events));
return $this;
}
/**
* Execute validation service.
*
* @param \Illuminate\Http\Request|array $input
* @param array $phrases
*
* @return \Illuminate\Contracts\Validation\Validator
*/
public function validate($input, array $phrases = []): ValidatorContract
{
return $this->runValidation($input, $phrases, $this->localEvents);
}
/**
* Get validation events.
*
* @return array
*/
public function getValidationEvents(): array
{
return $this->events;
}
/**
* Get validation phrases.
*
* @return array
*/
public function getValidationPhrases(): array
{
return $this->phrases;
}
/**
* Get validation rules.
*
* @return array
*/
public function getValidationRules(): array
{
return $this->rules;
}
}