File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,5 +11,6 @@ enum PhpTypes: string
1111 case Double = "double " ;
1212 case Object = "object " ;
1313 case Null = "NULL " ;
14+ case Bool = "boolean " ;
1415}
1516// @codingStandardsIgnoreEnd
Original file line number Diff line number Diff line change @@ -12,6 +12,11 @@ class VArray
1212 // validator used for elements
1313 private mixed $ nestedValidator ;
1414
15+ /**
16+ * Creates an array validator.
17+ * @param mixed $nestedValidator A validator that will be applied on all elements
18+ * (validator arrays are not supported).
19+ */
1520 public function __construct (mixed $ nestedValidator = null )
1621 {
1722 $ this ->nestedValidator = $ nestedValidator ;
@@ -40,7 +45,18 @@ public function getElementSwaggerType(): mixed
4045
4146 public function validate (mixed $ value )
4247 {
43- ///TODO: check if array, check content
48+ if (!is_array ($ value )) {
49+ return false ;
50+ }
51+
52+ // validate all elements if there is a nested validator
53+ if ($ this ->nestedValidator != null ) {
54+ foreach ($ value as $ element ) {
55+ if (!$ this ->nestedValidator ->validate ($ element )) {
56+ return false ;
57+ }
58+ }
59+ }
4460 return true ;
4561 }
4662}
Original file line number Diff line number Diff line change 22
33namespace App \Helpers \MetaFormats \Validators ;
44
5+ use App \Helpers \MetaFormats \MetaFormatHelper ;
56use App \Helpers \MetaFormats \PhpTypes ;
67use App \Helpers \MetaFormats \PrimitiveFormatValidators ;
78
@@ -11,7 +12,7 @@ class VBool
1112
1213 public function validate (mixed $ value )
1314 {
14- ///TODO: check if bool
15- return true ;
15+ // support stringified values as well
16+ return MetaFormatHelper:: checkType ( $ value , PhpTypes::Bool) || $ value == " true " || $ value == " false " ;
1617 }
1718}
Original file line number Diff line number Diff line change 22
33namespace App \Helpers \MetaFormats \Validators ;
44
5+ use App \Helpers \MetaFormats \MetaFormatHelper ;
56use App \Helpers \MetaFormats \PhpTypes ;
67use App \Helpers \MetaFormats \PrimitiveFormatValidators ;
78
@@ -11,7 +12,12 @@ class VDouble
1112
1213 public function validate (mixed $ value )
1314 {
14- ///TODO: check if float
15- return true ;
15+ // check if it is a double
16+ if (MetaFormatHelper::checkType ($ value , PhpTypes::Double)) {
17+ return true ;
18+ }
19+
20+ // the value may be a string containing the number
21+ return is_numeric ($ value );
1622 }
1723}
You can’t perform that action at this time.
0 commit comments