Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to callback rule #162

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
update(callback): Use rule key as rule name (#1)
This allows for multiple callback rules per item and also indexes the
`ErrorBag`, which is helpful for identifying what validation failures
exist.
  • Loading branch information
marcusorjames authored Aug 26, 2024
commit 8535eaa315d6321affc024d2315ac54cc0e4650f
5 changes: 4 additions & 1 deletion src/Validation.php
Original file line number Diff line number Diff line change
@@ -489,13 +489,16 @@ protected function resolveRules($rules): array
}
$params = [];


if (is_string($rule)) {
list($rulename, $params) = $this->parseRule($rule);
$validator = call_user_func_array($validatorFactory, array_merge([$rulename], $params));
} elseif ($rule instanceof Rule) {
$validator = $rule;
} elseif ($rule instanceof Closure) {
$validator = call_user_func_array($validatorFactory, ['callback', $rule]);
$ruleName = is_string($i) ? $i : 'callback';
$validator = call_user_func_array($validatorFactory, ['callback', $rule ]);
$validator->setKey($ruleName);
} else {
$ruleName = is_object($rule) ? get_class($rule) : gettype($rule);
$message = "Rule must be a string, Closure or '".Rule::class."' instance. ".$ruleName." given";