| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
namespace Illuminate\Validation\Concerns;
|
|
|
4 |
|
|
|
5 |
use Illuminate\Support\Arr;
|
|
|
6 |
|
|
|
7 |
trait ReplacesAttributes
|
|
|
8 |
{
|
|
|
9 |
/**
|
|
|
10 |
* Replace all place-holders for the accepted_if rule.
|
|
|
11 |
*
|
|
|
12 |
* @param string $message
|
|
|
13 |
* @param string $attribute
|
|
|
14 |
* @param string $rule
|
|
|
15 |
* @param array<int,string> $parameters
|
|
|
16 |
* @return string
|
|
|
17 |
*/
|
|
|
18 |
protected function replaceAcceptedIf($message, $attribute, $rule, $parameters)
|
|
|
19 |
{
|
|
|
20 |
$parameters[1] = $this->getDisplayableValue($parameters[0], Arr::get($this->data, $parameters[0]));
|
|
|
21 |
|
|
|
22 |
$parameters[0] = $this->getDisplayableAttribute($parameters[0]);
|
|
|
23 |
|
|
|
24 |
return str_replace([':other', ':value'], $parameters, $message);
|
|
|
25 |
}
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* Replace all place-holders for the declined_if rule.
|
|
|
29 |
*
|
|
|
30 |
* @param string $message
|
|
|
31 |
* @param string $attribute
|
|
|
32 |
* @param string $rule
|
|
|
33 |
* @param array<int,string> $parameters
|
|
|
34 |
* @return string
|
|
|
35 |
*/
|
|
|
36 |
protected function replaceDeclinedIf($message, $attribute, $rule, $parameters)
|
|
|
37 |
{
|
|
|
38 |
$parameters[1] = $this->getDisplayableValue($parameters[0], Arr::get($this->data, $parameters[0]));
|
|
|
39 |
|
|
|
40 |
$parameters[0] = $this->getDisplayableAttribute($parameters[0]);
|
|
|
41 |
|
|
|
42 |
return str_replace([':other', ':value'], $parameters, $message);
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
/**
|
|
|
46 |
* Replace all place-holders for the between rule.
|
|
|
47 |
*
|
|
|
48 |
* @param string $message
|
|
|
49 |
* @param string $attribute
|
|
|
50 |
* @param string $rule
|
|
|
51 |
* @param array<int,string> $parameters
|
|
|
52 |
* @return string
|
|
|
53 |
*/
|
|
|
54 |
protected function replaceBetween($message, $attribute, $rule, $parameters)
|
|
|
55 |
{
|
|
|
56 |
return str_replace([':min', ':max'], $parameters, $message);
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
/**
|
|
|
60 |
* Replace all place-holders for the date_format rule.
|
|
|
61 |
*
|
|
|
62 |
* @param string $message
|
|
|
63 |
* @param string $attribute
|
|
|
64 |
* @param string $rule
|
|
|
65 |
* @param array<int,string> $parameters
|
|
|
66 |
* @return string
|
|
|
67 |
*/
|
|
|
68 |
protected function replaceDateFormat($message, $attribute, $rule, $parameters)
|
|
|
69 |
{
|
|
|
70 |
return str_replace(':format', $parameters[0], $message);
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
/**
|
|
|
74 |
* Replace all place-holders for the decimal rule.
|
|
|
75 |
*
|
|
|
76 |
* @param string $message
|
|
|
77 |
* @param string $attribute
|
|
|
78 |
* @param string $rule
|
|
|
79 |
* @param array<int,int> $parameters
|
|
|
80 |
* @return string
|
|
|
81 |
*/
|
|
|
82 |
protected function replaceDecimal($message, $attribute, $rule, $parameters)
|
|
|
83 |
{
|
|
|
84 |
return str_replace(
|
|
|
85 |
':decimal',
|
|
|
86 |
isset($parameters[1])
|
|
|
87 |
? $parameters[0].'-'.$parameters[1]
|
|
|
88 |
: $parameters[0],
|
|
|
89 |
$message
|
|
|
90 |
);
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
/**
|
|
|
94 |
* Replace all place-holders for the different rule.
|
|
|
95 |
*
|
|
|
96 |
* @param string $message
|
|
|
97 |
* @param string $attribute
|
|
|
98 |
* @param string $rule
|
|
|
99 |
* @param array<int,string> $parameters
|
|
|
100 |
* @return string
|
|
|
101 |
*/
|
|
|
102 |
protected function replaceDifferent($message, $attribute, $rule, $parameters)
|
|
|
103 |
{
|
|
|
104 |
return $this->replaceSame($message, $attribute, $rule, $parameters);
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
/**
|
|
|
108 |
* Replace all place-holders for the digits rule.
|
|
|
109 |
*
|
|
|
110 |
* @param string $message
|
|
|
111 |
* @param string $attribute
|
|
|
112 |
* @param string $rule
|
|
|
113 |
* @param array<int,string> $parameters
|
|
|
114 |
* @return string
|
|
|
115 |
*/
|
|
|
116 |
protected function replaceDigits($message, $attribute, $rule, $parameters)
|
|
|
117 |
{
|
|
|
118 |
return str_replace(':digits', $parameters[0], $message);
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
/**
|
|
|
122 |
* Replace all place-holders for the digits (between) rule.
|
|
|
123 |
*
|
|
|
124 |
* @param string $message
|
|
|
125 |
* @param string $attribute
|
|
|
126 |
* @param string $rule
|
|
|
127 |
* @param array<int,string> $parameters
|
|
|
128 |
* @return string
|
|
|
129 |
*/
|
|
|
130 |
protected function replaceDigitsBetween($message, $attribute, $rule, $parameters)
|
|
|
131 |
{
|
|
|
132 |
return $this->replaceBetween($message, $attribute, $rule, $parameters);
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
/**
|
|
|
136 |
* Replace all place-holders for the min rule.
|
|
|
137 |
*
|
|
|
138 |
* @param string $message
|
|
|
139 |
* @param string $attribute
|
|
|
140 |
* @param string $rule
|
|
|
141 |
* @param array<int,string> $parameters
|
|
|
142 |
* @return string
|
|
|
143 |
*/
|
|
|
144 |
protected function replaceMin($message, $attribute, $rule, $parameters)
|
|
|
145 |
{
|
|
|
146 |
return str_replace(':min', $parameters[0], $message);
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
/**
|
|
|
150 |
* Replace all place-holders for the min digits rule.
|
|
|
151 |
*
|
|
|
152 |
* @param string $message
|
|
|
153 |
* @param string $attribute
|
|
|
154 |
* @param string $rule
|
|
|
155 |
* @param array<int,string> $parameters
|
|
|
156 |
* @return string
|
|
|
157 |
*/
|
|
|
158 |
protected function replaceMinDigits($message, $attribute, $rule, $parameters)
|
|
|
159 |
{
|
|
|
160 |
return str_replace(':min', $parameters[0], $message);
|
|
|
161 |
}
|
|
|
162 |
|
|
|
163 |
/**
|
|
|
164 |
* Replace all place-holders for the max rule.
|
|
|
165 |
*
|
|
|
166 |
* @param string $message
|
|
|
167 |
* @param string $attribute
|
|
|
168 |
* @param string $rule
|
|
|
169 |
* @param array<int,string> $parameters
|
|
|
170 |
* @return string
|
|
|
171 |
*/
|
|
|
172 |
protected function replaceMax($message, $attribute, $rule, $parameters)
|
|
|
173 |
{
|
|
|
174 |
return str_replace(':max', $parameters[0], $message);
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
/**
|
|
|
178 |
* Replace all place-holders for the max digits rule.
|
|
|
179 |
*
|
|
|
180 |
* @param string $message
|
|
|
181 |
* @param string $attribute
|
|
|
182 |
* @param string $rule
|
|
|
183 |
* @param array<int,string> $parameters
|
|
|
184 |
* @return string
|
|
|
185 |
*/
|
|
|
186 |
protected function replaceMaxDigits($message, $attribute, $rule, $parameters)
|
|
|
187 |
{
|
|
|
188 |
return str_replace(':max', $parameters[0], $message);
|
|
|
189 |
}
|
|
|
190 |
|
|
|
191 |
/**
|
| 399 |
lars |
192 |
* Replace all place-holders for the missing_if rule.
|
|
|
193 |
*
|
|
|
194 |
* @param string $message
|
|
|
195 |
* @param string $attribute
|
|
|
196 |
* @param string $rule
|
|
|
197 |
* @param array<int,string> $parameters
|
|
|
198 |
* @return string
|
|
|
199 |
*/
|
|
|
200 |
protected function replaceMissingIf($message, $attribute, $rule, $parameters)
|
|
|
201 |
{
|
|
|
202 |
$parameters[1] = $this->getDisplayableValue($parameters[0], Arr::get($this->data, $parameters[0]));
|
|
|
203 |
|
|
|
204 |
$parameters[0] = $this->getDisplayableAttribute($parameters[0]);
|
|
|
205 |
|
|
|
206 |
return str_replace([':other', ':value'], $parameters, $message);
|
|
|
207 |
}
|
|
|
208 |
|
|
|
209 |
/**
|
|
|
210 |
* Replace all place-holders for the missing_unless rule.
|
|
|
211 |
*
|
|
|
212 |
* @param string $message
|
|
|
213 |
* @param string $attribute
|
|
|
214 |
* @param string $rule
|
|
|
215 |
* @param array<int,string> $parameters
|
|
|
216 |
* @return string
|
|
|
217 |
*/
|
|
|
218 |
protected function replaceMissingUnless($message, $attribute, $rule, $parameters)
|
|
|
219 |
{
|
|
|
220 |
return $this->replaceMissingIf($message, $attribute, $rule, $parameters);
|
|
|
221 |
}
|
|
|
222 |
|
|
|
223 |
/**
|
|
|
224 |
* Replace all place-holders for the missing_with rule.
|
|
|
225 |
*
|
|
|
226 |
* @param string $message
|
|
|
227 |
* @param string $attribute
|
|
|
228 |
* @param string $rule
|
|
|
229 |
* @param array<int,string> $parameters
|
|
|
230 |
* @return string
|
|
|
231 |
*/
|
|
|
232 |
protected function replaceMissingWith($message, $attribute, $rule, $parameters)
|
|
|
233 |
{
|
|
|
234 |
return str_replace(':values', implode(' / ', $this->getAttributeList($parameters)), $message);
|
|
|
235 |
}
|
|
|
236 |
|
|
|
237 |
/**
|
|
|
238 |
* Replace all place-holders for the missing_with_all rule.
|
|
|
239 |
*
|
|
|
240 |
* @param string $message
|
|
|
241 |
* @param string $attribute
|
|
|
242 |
* @param string $rule
|
|
|
243 |
* @param array<int,string> $parameters
|
|
|
244 |
* @return string
|
|
|
245 |
*/
|
|
|
246 |
protected function replaceMissingWithAll($message, $attribute, $rule, $parameters)
|
|
|
247 |
{
|
|
|
248 |
return $this->replaceMissingWith($message, $attribute, $rule, $parameters);
|
|
|
249 |
}
|
|
|
250 |
|
|
|
251 |
/**
|
| 148 |
lars |
252 |
* Replace all place-holders for the multiple_of rule.
|
|
|
253 |
*
|
|
|
254 |
* @param string $message
|
|
|
255 |
* @param string $attribute
|
|
|
256 |
* @param string $rule
|
|
|
257 |
* @param array<int,string> $parameters
|
|
|
258 |
* @return string
|
|
|
259 |
*/
|
|
|
260 |
protected function replaceMultipleOf($message, $attribute, $rule, $parameters)
|
|
|
261 |
{
|
|
|
262 |
return str_replace(':value', $parameters[0] ?? '', $message);
|
|
|
263 |
}
|
|
|
264 |
|
|
|
265 |
/**
|
|
|
266 |
* Replace all place-holders for the in rule.
|
|
|
267 |
*
|
|
|
268 |
* @param string $message
|
|
|
269 |
* @param string $attribute
|
|
|
270 |
* @param string $rule
|
|
|
271 |
* @param array<int,string> $parameters
|
|
|
272 |
* @return string
|
|
|
273 |
*/
|
|
|
274 |
protected function replaceIn($message, $attribute, $rule, $parameters)
|
|
|
275 |
{
|
|
|
276 |
foreach ($parameters as &$parameter) {
|
|
|
277 |
$parameter = $this->getDisplayableValue($attribute, $parameter);
|
|
|
278 |
}
|
|
|
279 |
|
|
|
280 |
return str_replace(':values', implode(', ', $parameters), $message);
|
|
|
281 |
}
|
|
|
282 |
|
|
|
283 |
/**
|
|
|
284 |
* Replace all place-holders for the not_in rule.
|
|
|
285 |
*
|
|
|
286 |
* @param string $message
|
|
|
287 |
* @param string $attribute
|
|
|
288 |
* @param string $rule
|
|
|
289 |
* @param array<int,string> $parameters
|
|
|
290 |
* @return string
|
|
|
291 |
*/
|
|
|
292 |
protected function replaceNotIn($message, $attribute, $rule, $parameters)
|
|
|
293 |
{
|
|
|
294 |
return $this->replaceIn($message, $attribute, $rule, $parameters);
|
|
|
295 |
}
|
|
|
296 |
|
|
|
297 |
/**
|
|
|
298 |
* Replace all place-holders for the in_array rule.
|
|
|
299 |
*
|
|
|
300 |
* @param string $message
|
|
|
301 |
* @param string $attribute
|
|
|
302 |
* @param string $rule
|
|
|
303 |
* @param array<int,string> $parameters
|
|
|
304 |
* @return string
|
|
|
305 |
*/
|
|
|
306 |
protected function replaceInArray($message, $attribute, $rule, $parameters)
|
|
|
307 |
{
|
|
|
308 |
return str_replace(':other', $this->getDisplayableAttribute($parameters[0]), $message);
|
|
|
309 |
}
|
|
|
310 |
|
|
|
311 |
/**
|
|
|
312 |
* Replace all place-holders for the required_array_keys rule.
|
|
|
313 |
*
|
|
|
314 |
* @param string $message
|
|
|
315 |
* @param string $attribute
|
|
|
316 |
* @param string $rule
|
|
|
317 |
* @param array<int,string> $parameters
|
|
|
318 |
* @return string
|
|
|
319 |
*/
|
|
|
320 |
protected function replaceRequiredArrayKeys($message, $attribute, $rule, $parameters)
|
|
|
321 |
{
|
|
|
322 |
foreach ($parameters as &$parameter) {
|
|
|
323 |
$parameter = $this->getDisplayableValue($attribute, $parameter);
|
|
|
324 |
}
|
|
|
325 |
|
|
|
326 |
return str_replace(':values', implode(', ', $parameters), $message);
|
|
|
327 |
}
|
|
|
328 |
|
|
|
329 |
/**
|
|
|
330 |
* Replace all place-holders for the mimetypes rule.
|
|
|
331 |
*
|
|
|
332 |
* @param string $message
|
|
|
333 |
* @param string $attribute
|
|
|
334 |
* @param string $rule
|
|
|
335 |
* @param array<int,string> $parameters
|
|
|
336 |
* @return string
|
|
|
337 |
*/
|
|
|
338 |
protected function replaceMimetypes($message, $attribute, $rule, $parameters)
|
|
|
339 |
{
|
|
|
340 |
return str_replace(':values', implode(', ', $parameters), $message);
|
|
|
341 |
}
|
|
|
342 |
|
|
|
343 |
/**
|
|
|
344 |
* Replace all place-holders for the mimes rule.
|
|
|
345 |
*
|
|
|
346 |
* @param string $message
|
|
|
347 |
* @param string $attribute
|
|
|
348 |
* @param string $rule
|
|
|
349 |
* @param array<int,string> $parameters
|
|
|
350 |
* @return string
|
|
|
351 |
*/
|
|
|
352 |
protected function replaceMimes($message, $attribute, $rule, $parameters)
|
|
|
353 |
{
|
|
|
354 |
return str_replace(':values', implode(', ', $parameters), $message);
|
|
|
355 |
}
|
|
|
356 |
|
|
|
357 |
/**
|
|
|
358 |
* Replace all place-holders for the required_with rule.
|
|
|
359 |
*
|
|
|
360 |
* @param string $message
|
|
|
361 |
* @param string $attribute
|
|
|
362 |
* @param string $rule
|
|
|
363 |
* @param array<int,string> $parameters
|
|
|
364 |
* @return string
|
|
|
365 |
*/
|
|
|
366 |
protected function replaceRequiredWith($message, $attribute, $rule, $parameters)
|
|
|
367 |
{
|
|
|
368 |
return str_replace(':values', implode(' / ', $this->getAttributeList($parameters)), $message);
|
|
|
369 |
}
|
|
|
370 |
|
|
|
371 |
/**
|
|
|
372 |
* Replace all place-holders for the required_with_all rule.
|
|
|
373 |
*
|
|
|
374 |
* @param string $message
|
|
|
375 |
* @param string $attribute
|
|
|
376 |
* @param string $rule
|
|
|
377 |
* @param array<int,string> $parameters
|
|
|
378 |
* @return string
|
|
|
379 |
*/
|
|
|
380 |
protected function replaceRequiredWithAll($message, $attribute, $rule, $parameters)
|
|
|
381 |
{
|
|
|
382 |
return $this->replaceRequiredWith($message, $attribute, $rule, $parameters);
|
|
|
383 |
}
|
|
|
384 |
|
|
|
385 |
/**
|
|
|
386 |
* Replace all place-holders for the required_without rule.
|
|
|
387 |
*
|
|
|
388 |
* @param string $message
|
|
|
389 |
* @param string $attribute
|
|
|
390 |
* @param string $rule
|
|
|
391 |
* @param array<int,string> $parameters
|
|
|
392 |
* @return string
|
|
|
393 |
*/
|
|
|
394 |
protected function replaceRequiredWithout($message, $attribute, $rule, $parameters)
|
|
|
395 |
{
|
|
|
396 |
return $this->replaceRequiredWith($message, $attribute, $rule, $parameters);
|
|
|
397 |
}
|
|
|
398 |
|
|
|
399 |
/**
|
|
|
400 |
* Replace all place-holders for the required_without_all rule.
|
|
|
401 |
*
|
|
|
402 |
* @param string $message
|
|
|
403 |
* @param string $attribute
|
|
|
404 |
* @param string $rule
|
|
|
405 |
* @param array<int,string> $parameters
|
|
|
406 |
* @return string
|
|
|
407 |
*/
|
|
|
408 |
protected function replaceRequiredWithoutAll($message, $attribute, $rule, $parameters)
|
|
|
409 |
{
|
|
|
410 |
return $this->replaceRequiredWith($message, $attribute, $rule, $parameters);
|
|
|
411 |
}
|
|
|
412 |
|
|
|
413 |
/**
|
|
|
414 |
* Replace all place-holders for the size rule.
|
|
|
415 |
*
|
|
|
416 |
* @param string $message
|
|
|
417 |
* @param string $attribute
|
|
|
418 |
* @param string $rule
|
|
|
419 |
* @param array<int,string> $parameters
|
|
|
420 |
* @return string
|
|
|
421 |
*/
|
|
|
422 |
protected function replaceSize($message, $attribute, $rule, $parameters)
|
|
|
423 |
{
|
|
|
424 |
return str_replace(':size', $parameters[0], $message);
|
|
|
425 |
}
|
|
|
426 |
|
|
|
427 |
/**
|
|
|
428 |
* Replace all place-holders for the gt rule.
|
|
|
429 |
*
|
|
|
430 |
* @param string $message
|
|
|
431 |
* @param string $attribute
|
|
|
432 |
* @param string $rule
|
|
|
433 |
* @param array<int,string> $parameters
|
|
|
434 |
* @return string
|
|
|
435 |
*/
|
|
|
436 |
protected function replaceGt($message, $attribute, $rule, $parameters)
|
|
|
437 |
{
|
|
|
438 |
if (is_null($value = $this->getValue($parameters[0]))) {
|
|
|
439 |
return str_replace(':value', $this->getDisplayableAttribute($parameters[0]), $message);
|
|
|
440 |
}
|
|
|
441 |
|
|
|
442 |
return str_replace(':value', $this->getSize($attribute, $value), $message);
|
|
|
443 |
}
|
|
|
444 |
|
|
|
445 |
/**
|
|
|
446 |
* Replace all place-holders for the lt rule.
|
|
|
447 |
*
|
|
|
448 |
* @param string $message
|
|
|
449 |
* @param string $attribute
|
|
|
450 |
* @param string $rule
|
|
|
451 |
* @param array<int,string> $parameters
|
|
|
452 |
* @return string
|
|
|
453 |
*/
|
|
|
454 |
protected function replaceLt($message, $attribute, $rule, $parameters)
|
|
|
455 |
{
|
|
|
456 |
if (is_null($value = $this->getValue($parameters[0]))) {
|
|
|
457 |
return str_replace(':value', $this->getDisplayableAttribute($parameters[0]), $message);
|
|
|
458 |
}
|
|
|
459 |
|
|
|
460 |
return str_replace(':value', $this->getSize($attribute, $value), $message);
|
|
|
461 |
}
|
|
|
462 |
|
|
|
463 |
/**
|
|
|
464 |
* Replace all place-holders for the gte rule.
|
|
|
465 |
*
|
|
|
466 |
* @param string $message
|
|
|
467 |
* @param string $attribute
|
|
|
468 |
* @param string $rule
|
|
|
469 |
* @param array<int,string> $parameters
|
|
|
470 |
* @return string
|
|
|
471 |
*/
|
|
|
472 |
protected function replaceGte($message, $attribute, $rule, $parameters)
|
|
|
473 |
{
|
|
|
474 |
if (is_null($value = $this->getValue($parameters[0]))) {
|
|
|
475 |
return str_replace(':value', $this->getDisplayableAttribute($parameters[0]), $message);
|
|
|
476 |
}
|
|
|
477 |
|
|
|
478 |
return str_replace(':value', $this->getSize($attribute, $value), $message);
|
|
|
479 |
}
|
|
|
480 |
|
|
|
481 |
/**
|
|
|
482 |
* Replace all place-holders for the lte rule.
|
|
|
483 |
*
|
|
|
484 |
* @param string $message
|
|
|
485 |
* @param string $attribute
|
|
|
486 |
* @param string $rule
|
|
|
487 |
* @param array<int,string> $parameters
|
|
|
488 |
* @return string
|
|
|
489 |
*/
|
|
|
490 |
protected function replaceLte($message, $attribute, $rule, $parameters)
|
|
|
491 |
{
|
|
|
492 |
if (is_null($value = $this->getValue($parameters[0]))) {
|
|
|
493 |
return str_replace(':value', $this->getDisplayableAttribute($parameters[0]), $message);
|
|
|
494 |
}
|
|
|
495 |
|
|
|
496 |
return str_replace(':value', $this->getSize($attribute, $value), $message);
|
|
|
497 |
}
|
|
|
498 |
|
|
|
499 |
/**
|
|
|
500 |
* Replace all place-holders for the required_if rule.
|
|
|
501 |
*
|
|
|
502 |
* @param string $message
|
|
|
503 |
* @param string $attribute
|
|
|
504 |
* @param string $rule
|
|
|
505 |
* @param array<int,string> $parameters
|
|
|
506 |
* @return string
|
|
|
507 |
*/
|
|
|
508 |
protected function replaceRequiredIf($message, $attribute, $rule, $parameters)
|
|
|
509 |
{
|
|
|
510 |
$parameters[1] = $this->getDisplayableValue($parameters[0], Arr::get($this->data, $parameters[0]));
|
|
|
511 |
|
|
|
512 |
$parameters[0] = $this->getDisplayableAttribute($parameters[0]);
|
|
|
513 |
|
|
|
514 |
return str_replace([':other', ':value'], $parameters, $message);
|
|
|
515 |
}
|
|
|
516 |
|
|
|
517 |
/**
|
|
|
518 |
* Replace all place-holders for the required_if_accepted rule.
|
|
|
519 |
*
|
|
|
520 |
* @param string $message
|
|
|
521 |
* @param string $attribute
|
|
|
522 |
* @param string $rule
|
|
|
523 |
* @param array<int,string> $parameters
|
|
|
524 |
* @return string
|
|
|
525 |
*/
|
|
|
526 |
protected function replaceRequiredIfAccepted($message, $attribute, $rule, $parameters)
|
|
|
527 |
{
|
|
|
528 |
$parameters[0] = $this->getDisplayableAttribute($parameters[0]);
|
|
|
529 |
|
|
|
530 |
return str_replace([':other'], $parameters, $message);
|
|
|
531 |
}
|
|
|
532 |
|
|
|
533 |
/**
|
|
|
534 |
* Replace all place-holders for the required_unless rule.
|
|
|
535 |
*
|
|
|
536 |
* @param string $message
|
|
|
537 |
* @param string $attribute
|
|
|
538 |
* @param string $rule
|
|
|
539 |
* @param array<int,string> $parameters
|
|
|
540 |
* @return string
|
|
|
541 |
*/
|
|
|
542 |
protected function replaceRequiredUnless($message, $attribute, $rule, $parameters)
|
|
|
543 |
{
|
|
|
544 |
$other = $this->getDisplayableAttribute($parameters[0]);
|
|
|
545 |
|
|
|
546 |
$values = [];
|
|
|
547 |
|
|
|
548 |
foreach (array_slice($parameters, 1) as $value) {
|
|
|
549 |
$values[] = $this->getDisplayableValue($parameters[0], $value);
|
|
|
550 |
}
|
|
|
551 |
|
|
|
552 |
return str_replace([':other', ':values'], [$other, implode(', ', $values)], $message);
|
|
|
553 |
}
|
|
|
554 |
|
|
|
555 |
/**
|
|
|
556 |
* Replace all place-holders for the prohibited_if rule.
|
|
|
557 |
*
|
|
|
558 |
* @param string $message
|
|
|
559 |
* @param string $attribute
|
|
|
560 |
* @param string $rule
|
|
|
561 |
* @param array<int,string> $parameters
|
|
|
562 |
* @return string
|
|
|
563 |
*/
|
|
|
564 |
protected function replaceProhibitedIf($message, $attribute, $rule, $parameters)
|
|
|
565 |
{
|
|
|
566 |
$parameters[1] = $this->getDisplayableValue($parameters[0], Arr::get($this->data, $parameters[0]));
|
|
|
567 |
|
|
|
568 |
$parameters[0] = $this->getDisplayableAttribute($parameters[0]);
|
|
|
569 |
|
|
|
570 |
return str_replace([':other', ':value'], $parameters, $message);
|
|
|
571 |
}
|
|
|
572 |
|
|
|
573 |
/**
|
|
|
574 |
* Replace all place-holders for the prohibited_unless rule.
|
|
|
575 |
*
|
|
|
576 |
* @param string $message
|
|
|
577 |
* @param string $attribute
|
|
|
578 |
* @param string $rule
|
|
|
579 |
* @param array<int,string> $parameters
|
|
|
580 |
* @return string
|
|
|
581 |
*/
|
|
|
582 |
protected function replaceProhibitedUnless($message, $attribute, $rule, $parameters)
|
|
|
583 |
{
|
|
|
584 |
$other = $this->getDisplayableAttribute($parameters[0]);
|
|
|
585 |
|
|
|
586 |
$values = [];
|
|
|
587 |
|
|
|
588 |
foreach (array_slice($parameters, 1) as $value) {
|
|
|
589 |
$values[] = $this->getDisplayableValue($parameters[0], $value);
|
|
|
590 |
}
|
|
|
591 |
|
|
|
592 |
return str_replace([':other', ':values'], [$other, implode(', ', $values)], $message);
|
|
|
593 |
}
|
|
|
594 |
|
|
|
595 |
/**
|
|
|
596 |
* Replace all place-holders for the prohibited_with rule.
|
|
|
597 |
*
|
|
|
598 |
* @param string $message
|
|
|
599 |
* @param string $attribute
|
|
|
600 |
* @param string $rule
|
|
|
601 |
* @param array<int,string> $parameters
|
|
|
602 |
* @return string
|
|
|
603 |
*/
|
|
|
604 |
protected function replaceProhibits($message, $attribute, $rule, $parameters)
|
|
|
605 |
{
|
|
|
606 |
return str_replace(':other', implode(' / ', $this->getAttributeList($parameters)), $message);
|
|
|
607 |
}
|
|
|
608 |
|
|
|
609 |
/**
|
|
|
610 |
* Replace all place-holders for the same rule.
|
|
|
611 |
*
|
|
|
612 |
* @param string $message
|
|
|
613 |
* @param string $attribute
|
|
|
614 |
* @param string $rule
|
|
|
615 |
* @param array<int,string> $parameters
|
|
|
616 |
* @return string
|
|
|
617 |
*/
|
|
|
618 |
protected function replaceSame($message, $attribute, $rule, $parameters)
|
|
|
619 |
{
|
|
|
620 |
return str_replace(':other', $this->getDisplayableAttribute($parameters[0]), $message);
|
|
|
621 |
}
|
|
|
622 |
|
|
|
623 |
/**
|
|
|
624 |
* Replace all place-holders for the before rule.
|
|
|
625 |
*
|
|
|
626 |
* @param string $message
|
|
|
627 |
* @param string $attribute
|
|
|
628 |
* @param string $rule
|
|
|
629 |
* @param array<int,string> $parameters
|
|
|
630 |
* @return string
|
|
|
631 |
*/
|
|
|
632 |
protected function replaceBefore($message, $attribute, $rule, $parameters)
|
|
|
633 |
{
|
|
|
634 |
if (! strtotime($parameters[0])) {
|
|
|
635 |
return str_replace(':date', $this->getDisplayableAttribute($parameters[0]), $message);
|
|
|
636 |
}
|
|
|
637 |
|
|
|
638 |
return str_replace(':date', $this->getDisplayableValue($attribute, $parameters[0]), $message);
|
|
|
639 |
}
|
|
|
640 |
|
|
|
641 |
/**
|
|
|
642 |
* Replace all place-holders for the before_or_equal rule.
|
|
|
643 |
*
|
|
|
644 |
* @param string $message
|
|
|
645 |
* @param string $attribute
|
|
|
646 |
* @param string $rule
|
|
|
647 |
* @param array<int,string> $parameters
|
|
|
648 |
* @return string
|
|
|
649 |
*/
|
|
|
650 |
protected function replaceBeforeOrEqual($message, $attribute, $rule, $parameters)
|
|
|
651 |
{
|
|
|
652 |
return $this->replaceBefore($message, $attribute, $rule, $parameters);
|
|
|
653 |
}
|
|
|
654 |
|
|
|
655 |
/**
|
|
|
656 |
* Replace all place-holders for the after rule.
|
|
|
657 |
*
|
|
|
658 |
* @param string $message
|
|
|
659 |
* @param string $attribute
|
|
|
660 |
* @param string $rule
|
|
|
661 |
* @param array<int,string> $parameters
|
|
|
662 |
* @return string
|
|
|
663 |
*/
|
|
|
664 |
protected function replaceAfter($message, $attribute, $rule, $parameters)
|
|
|
665 |
{
|
|
|
666 |
return $this->replaceBefore($message, $attribute, $rule, $parameters);
|
|
|
667 |
}
|
|
|
668 |
|
|
|
669 |
/**
|
|
|
670 |
* Replace all place-holders for the after_or_equal rule.
|
|
|
671 |
*
|
|
|
672 |
* @param string $message
|
|
|
673 |
* @param string $attribute
|
|
|
674 |
* @param string $rule
|
|
|
675 |
* @param array<int,string> $parameters
|
|
|
676 |
* @return string
|
|
|
677 |
*/
|
|
|
678 |
protected function replaceAfterOrEqual($message, $attribute, $rule, $parameters)
|
|
|
679 |
{
|
|
|
680 |
return $this->replaceBefore($message, $attribute, $rule, $parameters);
|
|
|
681 |
}
|
|
|
682 |
|
|
|
683 |
/**
|
|
|
684 |
* Replace all place-holders for the date_equals rule.
|
|
|
685 |
*
|
|
|
686 |
* @param string $message
|
|
|
687 |
* @param string $attribute
|
|
|
688 |
* @param string $rule
|
|
|
689 |
* @param array<int,string> $parameters
|
|
|
690 |
* @return string
|
|
|
691 |
*/
|
|
|
692 |
protected function replaceDateEquals($message, $attribute, $rule, $parameters)
|
|
|
693 |
{
|
|
|
694 |
return $this->replaceBefore($message, $attribute, $rule, $parameters);
|
|
|
695 |
}
|
|
|
696 |
|
|
|
697 |
/**
|
|
|
698 |
* Replace all place-holders for the dimensions rule.
|
|
|
699 |
*
|
|
|
700 |
* @param string $message
|
|
|
701 |
* @param string $attribute
|
|
|
702 |
* @param string $rule
|
|
|
703 |
* @param array<int,string> $parameters
|
|
|
704 |
* @return string
|
|
|
705 |
*/
|
|
|
706 |
protected function replaceDimensions($message, $attribute, $rule, $parameters)
|
|
|
707 |
{
|
|
|
708 |
$parameters = $this->parseNamedParameters($parameters);
|
|
|
709 |
|
|
|
710 |
if (is_array($parameters)) {
|
|
|
711 |
foreach ($parameters as $key => $value) {
|
|
|
712 |
$message = str_replace(':'.$key, $value, $message);
|
|
|
713 |
}
|
|
|
714 |
}
|
|
|
715 |
|
|
|
716 |
return $message;
|
|
|
717 |
}
|
|
|
718 |
|
|
|
719 |
/**
|
|
|
720 |
* Replace all place-holders for the ends_with rule.
|
|
|
721 |
*
|
|
|
722 |
* @param string $message
|
|
|
723 |
* @param string $attribute
|
|
|
724 |
* @param string $rule
|
|
|
725 |
* @param array<int,string> $parameters
|
|
|
726 |
* @return string
|
|
|
727 |
*/
|
|
|
728 |
protected function replaceEndsWith($message, $attribute, $rule, $parameters)
|
|
|
729 |
{
|
|
|
730 |
foreach ($parameters as &$parameter) {
|
|
|
731 |
$parameter = $this->getDisplayableValue($attribute, $parameter);
|
|
|
732 |
}
|
|
|
733 |
|
|
|
734 |
return str_replace(':values', implode(', ', $parameters), $message);
|
|
|
735 |
}
|
|
|
736 |
|
|
|
737 |
/**
|
|
|
738 |
* Replace all place-holders for the doesnt_end_with rule.
|
|
|
739 |
*
|
|
|
740 |
* @param string $message
|
|
|
741 |
* @param string $attribute
|
|
|
742 |
* @param string $rule
|
|
|
743 |
* @param array<int,string> $parameters
|
|
|
744 |
* @return string
|
|
|
745 |
*/
|
|
|
746 |
protected function replaceDoesntEndWith($message, $attribute, $rule, $parameters)
|
|
|
747 |
{
|
|
|
748 |
foreach ($parameters as &$parameter) {
|
|
|
749 |
$parameter = $this->getDisplayableValue($attribute, $parameter);
|
|
|
750 |
}
|
|
|
751 |
|
|
|
752 |
return str_replace(':values', implode(', ', $parameters), $message);
|
|
|
753 |
}
|
|
|
754 |
|
|
|
755 |
/**
|
|
|
756 |
* Replace all place-holders for the starts_with rule.
|
|
|
757 |
*
|
|
|
758 |
* @param string $message
|
|
|
759 |
* @param string $attribute
|
|
|
760 |
* @param string $rule
|
|
|
761 |
* @param array<int,string> $parameters
|
|
|
762 |
* @return string
|
|
|
763 |
*/
|
|
|
764 |
protected function replaceStartsWith($message, $attribute, $rule, $parameters)
|
|
|
765 |
{
|
|
|
766 |
foreach ($parameters as &$parameter) {
|
|
|
767 |
$parameter = $this->getDisplayableValue($attribute, $parameter);
|
|
|
768 |
}
|
|
|
769 |
|
|
|
770 |
return str_replace(':values', implode(', ', $parameters), $message);
|
|
|
771 |
}
|
|
|
772 |
|
|
|
773 |
/**
|
|
|
774 |
* Replace all place-holders for the doesnt_start_with rule.
|
|
|
775 |
*
|
|
|
776 |
* @param string $message
|
|
|
777 |
* @param string $attribute
|
|
|
778 |
* @param string $rule
|
|
|
779 |
* @param array<int,string> $parameters
|
|
|
780 |
* @return string
|
|
|
781 |
*/
|
|
|
782 |
protected function replaceDoesntStartWith($message, $attribute, $rule, $parameters)
|
|
|
783 |
{
|
|
|
784 |
foreach ($parameters as &$parameter) {
|
|
|
785 |
$parameter = $this->getDisplayableValue($attribute, $parameter);
|
|
|
786 |
}
|
|
|
787 |
|
|
|
788 |
return str_replace(':values', implode(', ', $parameters), $message);
|
|
|
789 |
}
|
|
|
790 |
}
|