@@ -243,6 +243,9 @@ public function validate() : bool
243243 $ rule ['required ' ] = true ;
244244 }
245245
246+ // Add key/name to $rule
247+ $ rule ['name ' ] = $ name ;
248+
246249 // Check if value exists
247250 if ($ value = $ this ->values ->get ($ name , false )) {
248251 // Validate using type validators
@@ -328,9 +331,32 @@ public function hasErrors() : bool
328331 public function validateType ($ type , $ value , array $ rule = []) : bool
329332 {
330333 $ type = strtolower ($ type );
334+
335+ // Check for type[]
336+ $ arrayType = (substr ($ type , -2 ) == '[] ' );
337+ if ($ arrayType ) {
338+ $ type = substr ($ type , 0 , -2 );
339+ }
340+
331341 if (isset ($ this ->typeValidateFunctionMap [$ type ])) {
342+ if ($ arrayType ) {
343+ // Validate an array of values
344+ $ values = (array ) $ value ;
345+ foreach ($ values as $ index => $ value ) {
346+ if (!$ this ->{$ this ->typeValidateFunctionMap [$ type ]}($ value , $ rule )) {
347+ $ this ->setError ($ rule ['name ' ], "' $ value' failed to validate as ' $ type' " );
348+ }
349+ }
350+
351+ // Return true regardless of any errors to avoid default error
352+ // that is set when this method returns false
353+ return true ;
354+ }
355+
356+ // Validate the value
332357 return $ this ->{$ this ->typeValidateFunctionMap [$ type ]}($ value , $ rule );
333358 }
359+
334360 throw new \InvalidArgumentException ("Type ' $ type' is not a valid rule type " );
335361 }
336362
0 commit comments