1 | <?php |
||
8 | class DelegatedValidator |
||
9 | { |
||
10 | use AccessProtectedTrait; |
||
11 | /** |
||
12 | * The Validator resolved instance. |
||
13 | * |
||
14 | * @var \Illuminate\Validation\Validator |
||
15 | */ |
||
16 | protected $validator; |
||
17 | |||
18 | /** |
||
19 | * Closure to invoke non accessible Validator methods. |
||
20 | * |
||
21 | * @var Closure |
||
22 | */ |
||
23 | protected $validatorMethod; |
||
24 | |||
25 | /** |
||
26 | * DelegatedValidator constructor. |
||
27 | * @param \Illuminate\Validation\Validator $validator |
||
28 | */ |
||
29 | 18 | public function __construct(BaseValidator $validator) |
|
30 | { |
||
31 | 18 | $this->validator = $validator; |
|
32 | 18 | $this->validatorMethod = $this->createProtectedCaller($validator); |
|
33 | 18 | } |
|
34 | |||
35 | /** |
||
36 | * @param string $method |
||
37 | */ |
||
38 | 6 | private function callValidator($method, $args = []) |
|
39 | { |
||
40 | 6 | return $this->callProtected($this->validatorMethod, $method, $args); |
|
41 | } |
||
42 | |||
43 | /** |
||
44 | * Get current \Illuminate\Validation\Validator instance. |
||
45 | * |
||
46 | * @return \Illuminate\Validation\Validator |
||
47 | */ |
||
48 | 1 | public function getValidator() |
|
49 | { |
||
50 | 1 | return $this->validator; |
|
51 | } |
||
52 | |||
53 | /** |
||
54 | * Get the data under validation. |
||
55 | * |
||
56 | * @return array |
||
57 | */ |
||
58 | 1 | public function getData() |
|
59 | { |
||
60 | 1 | return $this->validator->getData(); |
|
61 | } |
||
62 | |||
63 | /** |
||
64 | * Set the data under validation. |
||
65 | * |
||
66 | * @param array |
||
67 | */ |
||
68 | 1 | public function setData($data) |
|
69 | { |
||
70 | 1 | $this->validator->setData($data); |
|
71 | 1 | } |
|
72 | |||
73 | /** |
||
74 | * Get the validation rules. |
||
75 | * |
||
76 | * @return array |
||
77 | */ |
||
78 | 1 | public function getRules() |
|
79 | { |
||
80 | 1 | return $this->validator->getRules(); |
|
81 | } |
||
82 | |||
83 | /** |
||
84 | * Get the files under validation. |
||
85 | * |
||
86 | * @return array |
||
87 | */ |
||
88 | 1 | public function getFiles() |
|
89 | { |
||
90 | 1 | return $this->validator->getFiles(); |
|
91 | } |
||
92 | |||
93 | /** |
||
94 | * Set the files under validation. |
||
95 | * |
||
96 | * @param array $files |
||
97 | * |
||
98 | * @return BaseValidator |
||
99 | */ |
||
100 | 1 | public function setFiles(array $files) |
|
101 | { |
||
102 | 1 | return $this->validator->setFiles($files); |
|
103 | } |
||
104 | |||
105 | /** |
||
106 | * Determine if a given rule implies the attribute is required. |
||
107 | * |
||
108 | * @param string $rule |
||
109 | * |
||
110 | * @return bool |
||
111 | */ |
||
112 | 1 | public function isImplicit($rule) |
|
116 | |||
117 | /** |
||
118 | * Replace all error message place-holders with actual values. |
||
119 | * |
||
120 | * @param string $message |
||
121 | * @param string $attribute |
||
122 | * @param string $rule |
||
123 | * @param array $parameters |
||
124 | * |
||
125 | * @return string |
||
126 | */ |
||
127 | 1 | public function doReplacements($message, $attribute, $rule, $parameters) |
|
131 | |||
132 | /** |
||
133 | * Determine if the given attribute has a rule in the given set. |
||
134 | * |
||
135 | * @param string $attribute |
||
136 | * @param string|array $rules |
||
137 | * |
||
138 | * @return bool |
||
139 | */ |
||
140 | 1 | public function hasRule($attribute, $rules) |
|
144 | |||
145 | /** |
||
146 | * Get the validation message for an attribute and rule. |
||
147 | * |
||
148 | * @param string $attribute |
||
149 | * @param string $rule |
||
150 | * |
||
151 | * @return string |
||
152 | */ |
||
153 | 1 | public function getMessage($attribute, $rule) |
|
157 | |||
158 | /** |
||
159 | * Extract the rule name and parameters from a rule. |
||
160 | * |
||
161 | * @param array|string $rules |
||
162 | * |
||
163 | * @return array |
||
164 | */ |
||
165 | 1 | public function parseRule($rules) |
|
169 | |||
170 | /** |
||
171 | * Explode the rules into an array of rules. |
||
172 | * |
||
173 | * @param string|array $rules |
||
174 | * @return array |
||
175 | */ |
||
176 | 1 | public function explodeRules($rules) |
|
177 | { |
||
180 | |||
181 | /** |
||
182 | * Add conditions to a given field based on a Closure. |
||
183 | * |
||
184 | * @param string $attribute |
||
185 | * @param string|array $rules |
||
186 | * @param callable $callback |
||
187 | * @return void |
||
188 | */ |
||
189 | 1 | public function sometimes($attribute, $rules, callable $callback) |
|
193 | |||
194 | /** |
||
195 | * Delegate method calls to validator instance. |
||
196 | * |
||
197 | * @param $method |
||
198 | * @param $params |
||
199 | * |
||
200 | * @return mixed |
||
201 | */ |
||
202 | 1 | public function __call($method, $params) |
|
208 | } |
||
209 |