Skip to content

Commit

Permalink
master: Корректная обработка вилдкардов валидации при фильтрации вход…
Browse files Browse the repository at this point in the history
…ных данных
  • Loading branch information
Pavel committed Apr 23, 2018
1 parent 4cc02b7 commit 198a25a
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/Traits/JsonRpcController.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,36 @@ protected function extractInputFromRules($data, array $rules)
}

$result = [];

$additional = [];
$arrays = [];
$isGlobalArray = false;

foreach ($rules as $rule => $value) {
if (Str::contains($rule, '.')) {
$attributes = explode('.', $rule);
$rule = array_shift($attributes);
$key = implode('.', $attributes);

if (array_key_exists($rule, $data)) {
$key = implode('.', $attributes);
if (\is_array($data) && array_key_exists($rule, $data)) {
$additional[$rule][$key] = $value;
} elseif ($rule === '*' and \is_array($data)) {
$arrays[$key] = $value;
}
} elseif (array_key_exists($rule, $data)) {
} elseif (\is_array($data) && array_key_exists($rule, $data)) {
$result[$rule] = $data[$rule];
} elseif ($rule === '*' and \is_array($data)) {
$isGlobalArray = true;
}
}

if (!empty($arrays)) {
$result = [];
foreach ($data as $item) {
$result[] = $this->extractInputFromRules($item, $arrays);
}
return $result;
} elseif ($isGlobalArray) {
return $data;
}

foreach ($additional as $key => $item) {
Expand Down

0 comments on commit 198a25a

Please sign in to comment.