2323 */
2424class SchemaConstraint extends Constraint
2525{
26+ const DEFAULT_SCHEMA_SPEC = 'http://json-schema.org/draft-04/schema# ' ;
27+
2628 /**
2729 * {@inheritdoc}
2830 */
@@ -42,13 +44,16 @@ public function check(&$element, $schema = null, JsonPointer $path = null, $i =
4244 throw new InvalidArgumentException ('no schema found to verify against ' );
4345 }
4446
45- // validate schema against whatever is defined in $validationSchema->$schema
47+ // validate schema against whatever is defined in $validationSchema->$schema. If no
48+ // schema is defined, assume self::DEFAULT_SCHEMA_SPEC (currently draft-04).
4649 if ($ this ->factory ->getConfig (self ::CHECK_MODE_VALIDATE_SCHEMA )) {
4750 if (!$ this ->getTypeCheck ()->isObject ($ validationSchema )) {
4851 throw new RuntimeException ('cannot validate non-object schema ' );
4952 }
50- if (!$ this ->getTypeCheck ()->propertyExists ($ validationSchema , '$schema ' )) {
51- throw new RuntimeException ('$schema is not set ' );
53+ if ($ this ->getTypeCheck ()->propertyExists ($ validationSchema , '$schema ' )) {
54+ $ schemaSpec = $ this ->getTypeCheck ()->propertyGet ($ validationSchema , '$schema ' );
55+ } else {
56+ $ schemaSpec = self ::DEFAULT_SCHEMA_SPEC ;
5257 }
5358
5459 // preload standard schema specs
@@ -58,7 +63,6 @@ public function check(&$element, $schema = null, JsonPointer $path = null, $i =
5863 'http://json-schema.org/draft-04/schema ' => 'json-schema-draft-04.json ' ,
5964 'http://json-schema.org/draft-04/schema# ' => 'json-schema-draft-04.json '
6065 );
61- $ schemaSpec = $ this ->getTypeCheck ()->propertyGet ($ validationSchema , '$schema ' );
6266 $ schemaStorage = $ this ->factory ->getSchemaStorage ();
6367 foreach ($ preload as $ schemaID => $ schemaFile ) {
6468 $ schemaStorage ->addSchema (
0 commit comments