Skip to content

Commit d01dfd7

Browse files
iReddskenjis
authored andcommitted
Validation with wildcard keys.
Signed-off-by: Andrey Pyzhikov <5071@mail.ru>
1 parent 051a578 commit d01dfd7

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

‎system/Validation/Validation.php‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,16 @@ public function run(?array $data = null, ?string $group = null, ?string $dbGroup
145145
$rules = $this->splitRules($rules);
146146
}
147147

148-
$values = strpos($field, '*') !== false
149-
? array_filter(array_flatten_with_dots($data), static fn ($key) => preg_match(
148+
if (strpos($field, '*') !== false) {
149+
$values = array_filter(array_flatten_with_dots($data), static fn ($key) => preg_match(
150150
'/^' . str_replace('\.\*', '\..+', preg_quote($field, '/')) . '$/',
151151
$key
152-
), ARRAY_FILTER_USE_KEY)
153-
: dot_array_search($field, $data);
152+
), ARRAY_FILTER_USE_KEY);
153+
// if keys not found
154+
$values = $values ?: [$field => null];
155+
} else {
156+
$values = dot_array_search($field, $data);
157+
}
154158

155159
if ($values === []) {
156160
// We'll process the values right away if an empty array

0 commit comments

Comments
 (0)