Beispiel #1
0
 private function resolve($schema, $parents = array())
 {
     $result = $schema;
     if ($ref = JsonUtils::get($schema, '$ref')) {
         $refSchema = JsonUtils::get($this->references, $ref);
         if (in_array($ref, $parents)) {
             throw new \RuntimeException('Circular reference to ref ' . $ref);
         } elseif (JsonUtils::get($refSchema, '$ref')) {
             $parents[] = $ref;
             $result = $this->resolve($refSchema, $parents);
         } else {
             $result = $refSchema;
         }
     }
     return $result;
 }
Beispiel #2
0
 protected function validateObjectChildren($data, $schema, $additional)
 {
     if (true === $additional) {
         $additional = new \stdClass();
     }
     $p = JsonUtils::get($schema, 'properties', new \stdClass());
     $pp = JsonUtils::get($schema, 'patternProperties', new \stdClass());
     foreach ($data as $key => $value) {
         $child = array();
         if (isset($p->{$key})) {
             $child[] = $p->{$key};
         }
         foreach ($pp as $regex => $val) {
             if ($this->match($regex, $key)) {
                 $child[] = $val;
             }
         }
         if (!$child && $additional) {
             $child[] = $additional;
         }
         foreach ($child as $subSchema) {
             $this->validateChild($value, $subSchema, $key);
         }
     }
 }