Skip to content

Commit 3ea0c6a

Browse files
committed
modify: put the codition that don't have dot in the needed area.
1 parent b8f15b6 commit 3ea0c6a

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

system/Validation/Rules.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ public function required_with($str = null, ?string $fields = null, array $data =
282282
*/
283283
public function required_without($str = null, ?string $fields = null, array $data = [], ?string $error = null, ?string $keyField = null): bool
284284
{
285-
if ($fields === null || empty($data) || $keyField === null) {
286-
throw new InvalidArgumentException('You must supply the parameters: fields, data, keyField.');
285+
if ($fields === null || empty($data)) {
286+
throw new InvalidArgumentException('You must supply the parameters: fields, data');
287287
}
288288

289289
// If the field is present we can safely assume that
@@ -298,19 +298,21 @@ public function required_without($str = null, ?string $fields = null, array $dat
298298

299299
$nowKeyField = 0;
300300

301-
if (strpos($keyField, '.') !== false) {
302-
$keyFieldArray = explode('.', $keyField);
303-
$nowKeyField = $keyFieldArray[1];
304-
}
305-
306301
// Still here? Then we fail this test if
307302
// any of the fields are not present in $data
308303
foreach ($fields as $field) {
309304
if ((strpos($field, '.') === false) && (! array_key_exists($field, $data))) {
310305
return ! empty($data[$field]);
311306
}
312307
if (strpos($field, '.') !== false) {
313-
$fieldData = dot_array_search($field, $data);
308+
if ($keyField == null) {
309+
throw new InvalidArgumentException('You must supply the parameters: keyField');
310+
}
311+
312+
$fieldData = dot_array_search($field, $data);
313+
$keyFieldArray = explode('.', $keyField);
314+
$nowKeyField = $keyFieldArray[1];
315+
314316
if (is_array($fieldData)) {
315317
return ! empty(dot_array_search($field, $data)[$nowKeyField]);
316318
}

0 commit comments

Comments
 (0)