@@ -23,15 +23,15 @@ class UndefinedConstraint extends Constraint
23
23
/**
24
24
* {@inheritDoc}
25
25
*/
26
- public function check ($ value , $ schema = null , JsonPointer $ path = null , $ i = null ){
27
- $ this ->_check ($ value , $ schema , $ path , $ i );
26
+ public function check ($ value , $ schema = null , JsonPointer $ path = null , $ i = null , $ default = false ){
27
+ $ this ->_check ($ value , $ schema , $ path , $ i, false , $ default );
28
28
}
29
29
30
- public function coerce (&$ value , $ schema = null , JsonPointer $ path = null , $ i = null ){
31
- $ this ->_check ($ value , $ schema , $ path , $ i , true );
30
+ public function coerce (&$ value , $ schema = null , JsonPointer $ path = null , $ i = null , $ default = false ){
31
+ $ this ->_check ($ value , $ schema , $ path , $ i , true , $ default );
32
32
}
33
33
34
- protected function _check (&$ value , $ schema = null , JsonPointer $ path = null , $ i = null , $ coerce = false )
34
+ protected function _check (&$ value , $ schema = null , JsonPointer $ path = null , $ i = null , $ coerce = false , $ default = false )
35
35
{
36
36
if (is_null ($ schema ) || !is_object ($ schema )) {
37
37
return ;
@@ -40,13 +40,13 @@ protected function _check(&$value, $schema = null, JsonPointer $path = null, $i
40
40
$ path = $ this ->incrementPath ($ path ?: new JsonPointer ('' ), $ i );
41
41
42
42
// check special properties
43
- $ this ->validateCommonProperties ($ value , $ schema , $ path , $ i , $ coerce );
43
+ $ this ->validateCommonProperties ($ value , $ schema , $ path , $ i , $ coerce, $ default );
44
44
45
45
// check allOf, anyOf, and oneOf properties
46
- $ this ->validateOfProperties ($ value , $ schema , $ path , '' , $ coerce );
46
+ $ this ->validateOfProperties ($ value , $ schema , $ path , '' , $ coerce, $ default );
47
47
48
48
// check known types
49
- $ this ->validateTypes ($ value , $ schema , $ path , $ i , $ coerce );
49
+ $ this ->validateTypes ($ value , $ schema , $ path , $ i , $ coerce, $ default );
50
50
}
51
51
52
52
/**
@@ -58,7 +58,7 @@ protected function _check(&$value, $schema = null, JsonPointer $path = null, $i
58
58
* @param string $i
59
59
* @param boolean $coerce
60
60
*/
61
- public function validateTypes (&$ value , $ schema = null , JsonPointer $ path , $ i = null , $ coerce = false )
61
+ public function validateTypes (&$ value , $ schema = null , JsonPointer $ path , $ i = null , $ coerce = false , $ default = false )
62
62
{
63
63
// check array
64
64
if ($ this ->getTypeCheck ()->isArray ($ value )) {
@@ -73,7 +73,7 @@ public function validateTypes(&$value, $schema = null, JsonPointer $path, $i = n
73
73
$ path ,
74
74
isset ($ schema ->additionalProperties ) ? $ schema ->additionalProperties : null ,
75
75
isset ($ schema ->patternProperties ) ? $ schema ->patternProperties : null ,
76
- $ coerce
76
+ $ coerce, $ default
77
77
);
78
78
}
79
79
@@ -102,7 +102,7 @@ public function validateTypes(&$value, $schema = null, JsonPointer $path, $i = n
102
102
* @param string $i
103
103
* @param boolean $coerce
104
104
*/
105
- protected function validateCommonProperties (&$ value , $ schema = null , JsonPointer $ path , $ i = "" , $ coerce =false )
105
+ protected function validateCommonProperties (&$ value , $ schema = null , JsonPointer $ path , $ i = "" , $ coerce =false , $ default = false )
106
106
{
107
107
// if it extends another schema, it must pass that schema as well
108
108
if (isset ($ schema ->extends )) {
@@ -111,10 +111,10 @@ protected function validateCommonProperties(&$value, $schema = null, JsonPointer
111
111
}
112
112
if (is_array ($ schema ->extends )) {
113
113
foreach ($ schema ->extends as $ extends ) {
114
- $ this ->checkUndefined ($ value , $ extends , $ path , $ i , $ coerce );
114
+ $ this ->checkUndefined ($ value , $ extends , $ path , $ i , $ coerce, $ default );
115
115
}
116
116
} else {
117
- $ this ->checkUndefined ($ value , $ schema ->extends , $ path , $ i , $ coerce );
117
+ $ this ->checkUndefined ($ value , $ schema ->extends , $ path , $ i , $ coerce, $ default );
118
118
}
119
119
}
120
120
@@ -162,7 +162,7 @@ protected function validateCommonProperties(&$value, $schema = null, JsonPointer
162
162
163
163
if (isset ($ schema ->not )) {
164
164
$ initErrors = $ this ->getErrors ();
165
- $ this ->checkUndefined ($ value , $ schema ->not , $ path , $ i , $ coerce );
165
+ $ this ->checkUndefined ($ value , $ schema ->not , $ path , $ i , $ coerce, $ default );
166
166
167
167
// if no new errors were raised then the instance validated against the "not" schema
168
168
if (count ($ this ->getErrors ()) == count ($ initErrors )) {
@@ -187,7 +187,7 @@ protected function validateCommonProperties(&$value, $schema = null, JsonPointer
187
187
* @param string $i
188
188
* @param boolean $coerce
189
189
*/
190
- protected function validateOfProperties (&$ value , $ schema , JsonPointer $ path , $ i = "" , $ coerce = false )
190
+ protected function validateOfProperties (&$ value , $ schema , JsonPointer $ path , $ i = "" , $ coerce = false , $ default = false )
191
191
{
192
192
// Verify type
193
193
if ($ value instanceof UndefinedConstraint) {
@@ -198,7 +198,7 @@ protected function validateOfProperties(&$value, $schema, JsonPointer $path, $i
198
198
$ isValid = true ;
199
199
foreach ($ schema ->allOf as $ allOf ) {
200
200
$ initErrors = $ this ->getErrors ();
201
- $ this ->checkUndefined ($ value , $ allOf , $ path , $ i , $ coerce );
201
+ $ this ->checkUndefined ($ value , $ allOf , $ path , $ i , $ coerce, $ default );
202
202
$ isValid = $ isValid && (count ($ this ->getErrors ()) == count ($ initErrors ));
203
203
}
204
204
if (!$ isValid ) {
@@ -211,7 +211,7 @@ protected function validateOfProperties(&$value, $schema, JsonPointer $path, $i
211
211
$ startErrors = $ this ->getErrors ();
212
212
foreach ($ schema ->anyOf as $ anyOf ) {
213
213
$ initErrors = $ this ->getErrors ();
214
- $ this ->checkUndefined ($ value , $ anyOf , $ path , $ i , $ coerce );
214
+ $ this ->checkUndefined ($ value , $ anyOf , $ path , $ i , $ coerce, $ default );
215
215
if ($ isValid = (count ($ this ->getErrors ()) == count ($ initErrors ))) {
216
216
break ;
217
217
}
@@ -229,7 +229,7 @@ protected function validateOfProperties(&$value, $schema, JsonPointer $path, $i
229
229
$ startErrors = $ this ->getErrors ();
230
230
foreach ($ schema ->oneOf as $ oneOf ) {
231
231
$ this ->errors = array ();
232
- $ this ->checkUndefined ($ value , $ oneOf , $ path , $ i , $ coerce );
232
+ $ this ->checkUndefined ($ value , $ oneOf , $ path , $ i , $ coerce, $ default );
233
233
if (count ($ this ->getErrors ()) == 0 ) {
234
234
$ matchedSchemas ++;
235
235
}
0 commit comments