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 | 16 | public function __construct(BaseValidator $validator) |
|
30 | { |
||
31 | 16 | $this->validator = $validator; |
|
32 | 16 | $this->validatorMethod = $this->createProtectedCaller($validator); |
|
33 | 16 | } |
|
34 | |||
35 | 5 | /** |
|
36 | * @param string $method |
||
37 | 5 | */ |
|
38 | private function callValidator($method, $args = []) |
||
39 | { |
||
40 | return $this->callProtected($this->validatorMethod, $method, $args); |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * Get current \Illuminate\Validation\Validator instance. |
||
45 | 1 | * |
|
46 | * @return \Illuminate\Validation\Validator |
||
47 | 1 | */ |
|
48 | public function getValidator() |
||
49 | { |
||
50 | return $this->validator; |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * Get the data under validation. |
||
55 | 1 | * |
|
56 | * @return array |
||
57 | 1 | */ |
|
58 | public function getData() |
||
59 | { |
||
60 | return $this->validator->getData(); |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * Set the data under validation. |
||
65 | 1 | * |
|
66 | * @param array |
||
67 | 1 | */ |
|
68 | 1 | public function setData($data) |
|
69 | { |
||
70 | $this->validator->setData($data); |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * Get the validation rules. |
||
75 | 1 | * |
|
76 | * @return array |
||
77 | 1 | */ |
|
78 | public function getRules() |
||
79 | { |
||
80 | return $this->validator->getRules(); |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * Get the files under validation. |
||
85 | 1 | * |
|
86 | * @return array |
||
87 | 1 | */ |
|
88 | public function getFiles() |
||
89 | { |
||
90 | return $this->validator->getFiles(); |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * Set the files under validation. |
||
95 | * |
||
96 | * @param array $files |
||
97 | 1 | * |
|
98 | * @return BaseValidator |
||
99 | 1 | */ |
|
100 | public function setFiles(array $files) |
||
101 | { |
||
102 | 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 | 1 | * |
|
110 | * @return bool |
||
111 | 1 | */ |
|
112 | public function isImplicit($rule) |
||
113 | { |
||
114 | return $this->callValidator('isImplicit', [$rule]); |
||
115 | } |
||
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 | 1 | * |
|
125 | * @return string |
||
126 | 1 | */ |
|
127 | public function doReplacements($message, $attribute, $rule, $parameters) |
||
128 | { |
||
129 | return $this->callValidator('doReplacements', [$message, $attribute, $rule, $parameters]); |
||
130 | } |
||
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 | 1 | * |
|
138 | * @return bool |
||
139 | 1 | */ |
|
140 | public function hasRule($attribute, $rules) |
||
141 | { |
||
142 | return $this->callValidator('hasRule', [$attribute, $rules]); |
||
143 | } |
||
144 | |||
145 | /** |
||
146 | * Get the validation message for an attribute and rule. |
||
147 | * |
||
148 | * @param string $attribute |
||
149 | * @param string $rule |
||
150 | 1 | * |
|
151 | * @return string |
||
152 | 1 | */ |
|
153 | public function getMessage($attribute, $rule) |
||
154 | { |
||
155 | return $this->callValidator('getMessage', [$attribute, $rule]); |
||
156 | } |
||
157 | |||
158 | /** |
||
159 | * Extract the rule name and parameters from a rule. |
||
160 | * |
||
161 | * @param array|string $rules |
||
162 | 1 | * |
|
163 | * @return array |
||
164 | 1 | */ |
|
165 | public function parseRule($rules) |
||
166 | { |
||
167 | return $this->callValidator('parseRule', [$rules]); |
||
168 | } |
||
169 | |||
170 | /** |
||
171 | * Explode the rules into an array of rules. |
||
172 | * |
||
173 | * @param string|array $rules |
||
174 | * @return array |
||
175 | 1 | */ |
|
176 | public function explodeRules($rules) |
||
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 | public function sometimes($attribute, $rules, callable $callback) |
||
190 | { |
||
191 | $this->validator->sometimes($attribute, $rules, $callback); |
||
192 | } |
||
193 | |||
194 | /** |
||
195 | * Delegate method calls to validator instance. |
||
196 | * |
||
197 | * @param $method |
||
198 | * @param $params |
||
199 | * |
||
200 | * @return mixed |
||
201 | */ |
||
202 | public function __call($method, $params) |
||
208 | } |
||
209 |