@@ -56,6 +56,9 @@ class JsonSchema {
56
56
* @return unknown
57
57
*/
58
58
static public function validate ($ instance , $ schema = null , $ formatValidator = null ) {
59
+ self ::$ errors = array ();
60
+ self ::$ formatValidator = null ;
61
+
59
62
if ($ formatValidator ) self ::$ formatValidator = $ formatValidator ;
60
63
$ res = self ::_validate ($ instance ,$ schema ,false );
61
64
self ::$ formatValidator = null ;
@@ -146,6 +149,7 @@ static function checkArray($value,$schema,$path,$i,$_changing) {
146
149
}
147
150
148
151
static function checkProp ($ value , $ schema , $ path , $ i = '' , $ _changing = false ) {
152
+ Dbg::func (1 ,3 );
149
153
if (!is_object ($ schema )) {
150
154
return ;
151
155
}
@@ -199,10 +203,23 @@ static function checkProp($value, $schema, $path, $i = '', $_changing = false) {
199
203
}
200
204
//verify the itens on an array and min and max number of items.
201
205
if (is_array ($ value )) {
206
+ if (
207
+ self ::$ checkMode == self ::CHECK_MODE_TYPE_CAST &&
208
+ $ schema ->type == 'object '
209
+ ) {
210
+ self ::checkObj (
211
+ $ value ,
212
+ $ schema ->properties ,
213
+ $ path ,
214
+ isset ($ schema ->additionalProperties ) ? $ schema ->additionalProperties : null ,
215
+ $ _changing
216
+ );
217
+ }
202
218
self ::checkArray ($ value ,$ schema ,$ path ,$ i ,$ _changing );
203
219
}
204
220
############ verificar!
205
221
elseif (isset ($ schema ->properties ) && is_object ($ value )) {
222
+ Dbg::mark ('calling checkObj ' );
206
223
self ::checkObj (
207
224
$ value ,
208
225
$ schema ->properties ,
@@ -294,7 +311,12 @@ static function checkType($type, &$value, $path) {
294
311
&& $ type == 'integer '
295
312
) {
296
313
$ wrongType = !self ::checkTypeCast ($ type ,$ value );
297
- } elseif ($ type !== gettype ($ value )) {
314
+ } elseif (
315
+ self ::$ checkMode == self ::CHECK_MODE_TYPE_CAST
316
+ && $ type == 'object ' && is_array ($ value )
317
+ ) {
318
+ $ wrongType = false ;
319
+ } elseif ($ type !== gettype ($ value )) {
298
320
$ wrongType = true ;
299
321
}
300
322
}
@@ -361,7 +383,7 @@ static function checkTypeCast($type,&$value) {
361
383
362
384
static function checkObj ($ instance , $ objTypeDef , $ path , $ additionalProp ,$ _changing ) {
363
385
if ($ objTypeDef instanceOf StdClass) {
364
- if ( ! ($ instance instanceOf StdClass) || is_array ($ instance ) ) {
386
+ if ( ! (( $ instance instanceOf StdClass) || is_array ($ instance) ) ) {
365
387
self ::$ errors [] = array (
366
388
'property ' =>$ path ,
367
389
'message ' =>"an object is required "
@@ -370,7 +392,7 @@ static function checkObj($instance, $objTypeDef, $path, $additionalProp,$_changi
370
392
foreach ($ objTypeDef as $ i =>$ value ) {
371
393
$ value =
372
394
array_key_exists ($ i ,$ instance ) ?
373
- $ instance ->$ i :
395
+ ( is_array ( $ instance) ? $ instance [ $ i ] : $ instance ->$ i) :
374
396
new JsonSchemaUndefined ();
375
397
$ propDef = $ objTypeDef ->$ i ;
376
398
self ::checkProp ($ value ,$ propDef ,$ path ,$ i ,$ _changing );
@@ -395,7 +417,7 @@ static function checkObj($instance, $objTypeDef, $path, $additionalProp,$_changi
395
417
);
396
418
}
397
419
}
398
- $ value = $ instance ->$ i ;
420
+ $ value = is_array ( $ instance ) ? $ instance [ $ i ] : $ instance ->$ i ;
399
421
400
422
// To verify additional properties types.
401
423
if ($ objTypeDef && is_object ($ objTypeDef ) && !isset ($ objTypeDef ->$ i )) {
@@ -418,6 +440,10 @@ class Dbg {
418
440
419
441
static public $ quietMode = false ;
420
442
443
+ static function includeJqueryJs () {
444
+ echo "<script type='text/javascript' src='/js/jquery.js'></script> " ;
445
+ }
446
+
421
447
static function func ($ print = true , $ numStackSteps = 1 ) {
422
448
$ ar = debug_backtrace ();
423
449
$ ret = '' ;
@@ -440,7 +466,7 @@ static function mark($title,$print = true) {
440
466
return $ ret ;
441
467
}
442
468
443
- static function object ($ object ,$ linkTitle ,$ varDump = false ,$ print = true ) {
469
+ static function object ($ object ,$ linkTitle = ' object ' ,$ varDump = false ,$ print = true ) {
444
470
static $ divCount = 0 ;
445
471
$ divCount ++;
446
472
$ ar = debug_backtrace ();
0 commit comments