Skip to content

Commit 96e690c

Browse files
committed
fix: DBGroup is ignored in validation process while using placeholders
1 parent b5bea51 commit 96e690c

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

system/Validation/Validation.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ public function run(?array $data = null, ?string $group = null, ?string $dbGroup
190190
* Runs the validation process, returning true or false
191191
* determining whether validation was successful or not.
192192
*
193+
* @TODO the method signature is not good. Should make the checkValue()
194+
* method this method.
195+
*
193196
* @param array|bool|float|int|object|string|null $value
194197
* @param string[] $errors
195198
*/
@@ -200,6 +203,31 @@ public function check($value, string $rule, array $errors = []): bool
200203
return $this->setRule('check', null, $rule, $errors)->run(['check' => $value]);
201204
}
202205

206+
/**
207+
* Runs the validation process, returning true or false determining whether
208+
* validation was successful or not.
209+
*
210+
* @param array|bool|float|int|object|string|null $value
211+
* @param array|string $rules
212+
* @param string[] $errors
213+
* @param string|null $dbGroup The database group to use.
214+
*/
215+
private function checkValue($value, $rules, array $errors = [], $dbGroup = null): bool
216+
{
217+
$this->reset();
218+
219+
return $this->setRule(
220+
'check',
221+
null,
222+
$rules,
223+
$errors
224+
)->run(
225+
['check' => $value],
226+
null,
227+
$dbGroup
228+
);
229+
}
230+
203231
/**
204232
* Runs all of $rules against $field, until one fails, or
205233
* all of them have been processed. If one fails, it adds
@@ -682,6 +710,7 @@ protected function fillPlaceholders(array $rules, array $data): array
682710

683711
foreach ($placeholderFields as $field) {
684712
$validator ??= Services::validation(null, false);
713+
assert($validator instanceof Validation);
685714

686715
$placeholderRules = $rules[$field]['rules'] ?? null;
687716

@@ -702,7 +731,8 @@ protected function fillPlaceholders(array $rules, array $data): array
702731
}
703732

704733
// Validate the placeholder field
705-
if (! $validator->check($data[$field], implode('|', $placeholderRules))) {
734+
$dbGroup = $data['DBGroup'] ?? null;
735+
if (! $validator->checkValue($data[$field], $placeholderRules, [], $dbGroup)) {
706736
// if fails, do nothing
707737
continue;
708738
}

0 commit comments

Comments
 (0)