1111
1212namespace CodeIgniter \Validation ;
1313
14+ use Closure ;
1415use CodeIgniter \HTTP \IncomingRequest ;
1516use CodeIgniter \HTTP \RequestInterface ;
1617use CodeIgniter \Validation \Exceptions \ValidationException ;
@@ -195,7 +196,7 @@ public function check($value, string $rule, array $errors = []): bool
195196 *
196197 * @param array|string $value
197198 * @param array|null $rules
198- * @param array $data The array of data to validate, with `DBGroup`.
199+ * @param array|null $data The array of data to validate, with `DBGroup`.
199200 * @param string|null $originalField The original asterisk field name like "foo.*.bar".
200201 */
201202 protected function processRules (
@@ -277,7 +278,7 @@ protected function processRules(
277278 $ rules = array_diff ($ rules , ['permit_empty ' ]);
278279 }
279280
280- foreach ($ rules as $ rule ) {
281+ foreach ($ rules as $ i => $ rule ) {
281282 $ isCallable = is_callable ($ rule );
282283
283284 $ passed = false ;
@@ -333,7 +334,7 @@ protected function processRules(
333334
334335 // @phpstan-ignore-next-line $error may be set by rule methods.
335336 $ this ->errors [$ field ] = $ error ?? $ this ->getErrorMessage (
336- $ rule ,
337+ $ this -> isClosure ( $ rule ) ? $ i : $ rule ,
337338 $ field ,
338339 $ label ,
339340 $ param ,
@@ -348,6 +349,14 @@ protected function processRules(
348349 return true ;
349350 }
350351
352+ /**
353+ * @param Closure|string $rule
354+ */
355+ private function isClosure ($ rule ): bool
356+ {
357+ return $ rule instanceof Closure;
358+ }
359+
351360 /**
352361 * Is the array a string list `list<string>`?
353362 */
0 commit comments