@@ -866,19 +866,8 @@ public function offsetGet($option)
866
866
$ valid = false ;
867
867
868
868
foreach ($ this ->allowedTypes [$ option ] as $ type ) {
869
- $ type = isset (self ::$ typeAliases [$ type ]) ? self ::$ typeAliases [$ type ] : $ type ;
870
-
871
- if (function_exists ($ isFunction = 'is_ ' .$ type )) {
872
- if ($ isFunction ($ value )) {
873
- $ valid = true ;
874
- break ;
875
- }
876
-
877
- continue ;
878
- }
879
-
880
- if ($ value instanceof $ type ) {
881
- $ valid = true ;
869
+ $ valid = $ this ->verifyAllowedType ($ type , $ value );
870
+ if ($ valid ) {
882
871
break ;
883
872
}
884
873
}
@@ -890,7 +879,7 @@ public function offsetGet($option)
890
879
$ option ,
891
880
$ this ->formatValue ($ value ),
892
881
implode ('" or " ' , $ this ->allowedTypes [$ option ]),
893
- $ this ->formatTypeOf ($ value )
882
+ $ this ->formatTypeOf ($ value, $ offendingType )
894
883
));
895
884
}
896
885
}
@@ -964,6 +953,44 @@ public function offsetGet($option)
964
953
return $ value ;
965
954
}
966
955
956
+ /**
957
+ * Verify value is of the allowed type. Recursive method to support
958
+ * typed array notation like ClassName[], or scalar arrays (int[])
959
+ *
960
+ * @param string $type the required allowedType string
961
+ *
962
+ * @param mixed $value the value
963
+ *
964
+ * @return bool Whether or not $value if of the allowed type
965
+ *
966
+ */
967
+ private function verifyAllowedType ($ type , $ value )
968
+ {
969
+ $ valid = false ;
970
+
971
+ $ type = isset (self ::$ typeAliases [$ type ]) ? self ::$ typeAliases [$ type ] : $ type ;
972
+
973
+ if (substr ($ type , -2 ) === '[] ' ) {
974
+ if (is_array ($ value )) {
975
+ $ subType = substr ($ type , 0 , -2 );
976
+ foreach ($ value as $ v ) {
977
+ $ valid = $ this ->validateType ($ subType , $ v );
978
+ if (!$ valid ) {
979
+ break ;
980
+ }
981
+ }
982
+ }
983
+ } else if (function_exists ($ isFunction = 'is_ ' .$ type )) {
984
+ if ($ isFunction ($ value )) {
985
+ $ valid = true ;
986
+ }
987
+ } else if ($ value instanceof $ type ) {
988
+ $ valid = true ;
989
+ }
990
+
991
+ return $ valid ;
992
+ }
993
+
967
994
/**
968
995
* Returns whether a resolved option with the given name exists.
969
996
*
0 commit comments