@@ -23,15 +23,15 @@ class UndefinedConstraint extends Constraint
2323 /**
2424 * {@inheritDoc}
2525 */
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 );
2828 }
2929
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 );
3232 }
3333
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 )
3535 {
3636 if (is_null ($ schema ) || !is_object ($ schema )) {
3737 return ;
@@ -40,13 +40,13 @@ protected function _check(&$value, $schema = null, JsonPointer $path = null, $i
4040 $ path = $ this ->incrementPath ($ path ?: new JsonPointer ('' ), $ i );
4141
4242 // check special properties
43- $ this ->validateCommonProperties ($ value , $ schema , $ path , $ i , $ coerce );
43+ $ this ->validateCommonProperties ($ value , $ schema , $ path , $ i , $ coerce, $ default );
4444
4545 // check allOf, anyOf, and oneOf properties
46- $ this ->validateOfProperties ($ value , $ schema , $ path , '' , $ coerce );
46+ $ this ->validateOfProperties ($ value , $ schema , $ path , '' , $ coerce, $ default );
4747
4848 // check known types
49- $ this ->validateTypes ($ value , $ schema , $ path , $ i , $ coerce );
49+ $ this ->validateTypes ($ value , $ schema , $ path , $ i , $ coerce, $ default );
5050 }
5151
5252 /**
@@ -58,7 +58,7 @@ protected function _check(&$value, $schema = null, JsonPointer $path = null, $i
5858 * @param string $i
5959 * @param boolean $coerce
6060 */
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 )
6262 {
6363 // check array
6464 if ($ this ->getTypeCheck ()->isArray ($ value )) {
@@ -73,7 +73,7 @@ public function validateTypes(&$value, $schema = null, JsonPointer $path, $i = n
7373 $ path ,
7474 isset ($ schema ->additionalProperties ) ? $ schema ->additionalProperties : null ,
7575 isset ($ schema ->patternProperties ) ? $ schema ->patternProperties : null ,
76- $ coerce
76+ $ coerce, $ default
7777 );
7878 }
7979
@@ -102,7 +102,7 @@ public function validateTypes(&$value, $schema = null, JsonPointer $path, $i = n
102102 * @param string $i
103103 * @param boolean $coerce
104104 */
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 )
106106 {
107107 // if it extends another schema, it must pass that schema as well
108108 if (isset ($ schema ->extends )) {
@@ -111,10 +111,10 @@ protected function validateCommonProperties(&$value, $schema = null, JsonPointer
111111 }
112112 if (is_array ($ schema ->extends )) {
113113 foreach ($ schema ->extends as $ extends ) {
114- $ this ->checkUndefined ($ value , $ extends , $ path , $ i , $ coerce );
114+ $ this ->checkUndefined ($ value , $ extends , $ path , $ i , $ coerce, $ default );
115115 }
116116 } else {
117- $ this ->checkUndefined ($ value , $ schema ->extends , $ path , $ i , $ coerce );
117+ $ this ->checkUndefined ($ value , $ schema ->extends , $ path , $ i , $ coerce, $ default );
118118 }
119119 }
120120
@@ -162,7 +162,7 @@ protected function validateCommonProperties(&$value, $schema = null, JsonPointer
162162
163163 if (isset ($ schema ->not )) {
164164 $ initErrors = $ this ->getErrors ();
165- $ this ->checkUndefined ($ value , $ schema ->not , $ path , $ i , $ coerce );
165+ $ this ->checkUndefined ($ value , $ schema ->not , $ path , $ i , $ coerce, $ default );
166166
167167 // if no new errors were raised then the instance validated against the "not" schema
168168 if (count ($ this ->getErrors ()) == count ($ initErrors )) {
@@ -187,7 +187,7 @@ protected function validateCommonProperties(&$value, $schema = null, JsonPointer
187187 * @param string $i
188188 * @param boolean $coerce
189189 */
190- protected function validateOfProperties (&$ value , $ schema , JsonPointer $ path , $ i = "" , $ coerce = false )
190+ protected function validateOfProperties (&$ value , $ schema , JsonPointer $ path , $ i = "" , $ coerce = false , $ default = false )
191191 {
192192 // Verify type
193193 if ($ value instanceof UndefinedConstraint) {
@@ -198,7 +198,7 @@ protected function validateOfProperties(&$value, $schema, JsonPointer $path, $i
198198 $ isValid = true ;
199199 foreach ($ schema ->allOf as $ allOf ) {
200200 $ initErrors = $ this ->getErrors ();
201- $ this ->checkUndefined ($ value , $ allOf , $ path , $ i , $ coerce );
201+ $ this ->checkUndefined ($ value , $ allOf , $ path , $ i , $ coerce, $ default );
202202 $ isValid = $ isValid && (count ($ this ->getErrors ()) == count ($ initErrors ));
203203 }
204204 if (!$ isValid ) {
@@ -211,7 +211,7 @@ protected function validateOfProperties(&$value, $schema, JsonPointer $path, $i
211211 $ startErrors = $ this ->getErrors ();
212212 foreach ($ schema ->anyOf as $ anyOf ) {
213213 $ initErrors = $ this ->getErrors ();
214- $ this ->checkUndefined ($ value , $ anyOf , $ path , $ i , $ coerce );
214+ $ this ->checkUndefined ($ value , $ anyOf , $ path , $ i , $ coerce, $ default );
215215 if ($ isValid = (count ($ this ->getErrors ()) == count ($ initErrors ))) {
216216 break ;
217217 }
@@ -229,7 +229,7 @@ protected function validateOfProperties(&$value, $schema, JsonPointer $path, $i
229229 $ startErrors = $ this ->getErrors ();
230230 foreach ($ schema ->oneOf as $ oneOf ) {
231231 $ this ->errors = array ();
232- $ this ->checkUndefined ($ value , $ oneOf , $ path , $ i , $ coerce );
232+ $ this ->checkUndefined ($ value , $ oneOf , $ path , $ i , $ coerce, $ default );
233233 if (count ($ this ->getErrors ()) == 0 ) {
234234 $ matchedSchemas ++;
235235 }
0 commit comments