Skip to content

Commit 595baeb

Browse files
author
Harrison Ifeanyichukwu
committed
refactor: use array of string keys to enable fallbacks
1 parent fb37516 commit 595baeb

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/Handler.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,18 @@ public function runDBChecks(bool $required, string $field, $value, array $db_che
242242
//if there is no query, set the field key and the params key
243243
if (!array_key_exists('query', $db_check))
244244
{
245-
$db_check['field'] = Util::value('field', $db_check, is_int($value)? 'id' : $field); //defaults to id
246-
$db_check['params'] = Util::arrayValue('params', $db_check, [$value]); //defaults to value
245+
$db_check['field'] = Util::value(
246+
'field',
247+
$db_check,
248+
is_int($value)? 'id' : $this->resolveModelFieldName($field)
249+
);
250+
$db_check['params'] = Util::arrayValue(
251+
'params',
252+
$db_check,
253+
[$value]
254+
);
247255
}
256+
$db_check['params'] = Util::arrayValue('params', $db_check);
248257

249258
$check_if = $db_check['if'];
250259
$method = Util::value($check_if, $this->getDBChecksMethodMap(), 'null');
@@ -674,17 +683,17 @@ protected function processRules()
674683

675684
$this->_rule_options[$field]['type'] = $this->_filters[$field]['type'] = $type;
676685

677-
$require_if = Util::arrayValue('requireIf', $rule, []);
678-
$condition = Util::value('condition', $require_if, '');
686+
$required_if = Util::arrayValue(['requiredIf', 'requireIf'], $rule, []);
687+
$condition = Util::value('condition', $required_if, '');
679688

680689
if ($condition !== '')
681690
{
682691
$required = false;
683692

684-
$_field = Util::value('field', $require_if, '');
693+
$_field = Util::value('field', $required_if, '');
685694
$_field_value = Util::value($_field, $this->_source);
686695

687-
$_value = Util::value('value', $require_if, '');
696+
$_value = Util::value('value', $required_if, '');
688697

689698
//checkbox and radio inputs are only set if they are checked
690699
switch(strtolower($condition))
@@ -713,7 +722,7 @@ protected function processRules()
713722
}
714723
$rule['required'] = $required;
715724
}
716-
Util::unsetFromArray('requireIf', $rule);
725+
Util::unsetFromArray(['requiredIf', 'requireIf'], $rule);
717726

718727
//boolean fields are optional by default
719728
if (Util::keyNotSetOrTrue('required', $rule) && $type !== 'bool')

0 commit comments

Comments
 (0)