Esempio n. 1
0
 private function resolve($schema, $parents = array())
 {
     $result = $schema;
     if ($ref = Utils::get($schema, '$ref')) {
         $refSchema = Utils::get($this->references, $ref);
         if (in_array($ref, $parents)) {
             throw new \RuntimeException('Circular reference to ref ' . $ref);
         } elseif (Utils::get($refSchema, '$ref')) {
             $parents[] = $ref;
             $result = $this->resolve($refSchema, $parents);
         } else {
             $result = $refSchema;
         }
     }
     return $result;
 }
Esempio n. 2
0
 public static function validateArchiveData($archiveData)
 {
     if (!self::$schemaUri) {
         self::$schemaUri = __DIR__ . '/archive-schema.json';
     }
     $document = new Document();
     // have to do a encode+decode so that json objects decoded as arrays from Guzzle
     // are re-encoded as objects instead
     $document->loadData(json_decode(json_encode($archiveData)));
     $document->loadSchema(self::$schemaUri);
     // JSON Pointers are supported for the validation using this library, this is a hack
     $document->loadSchema(JsonUtils::get(JsonUtils::get($document->schema->data, 'definitions'), 'archive'));
     if (!$document->validate()) {
         throw new InvalidArgumentException('The archive data provided is not valid. Errors:' . $document->lastError . ' archiveData:' . print_r($archiveData, true));
     }
 }
Esempio n. 3
0
 protected function validateObjectChildren($data, $schema, $additional)
 {
     if (true === $additional) {
         $additional = new \stdClass();
     }
     $p = Utils::get($schema, 'properties', new \stdClass());
     $pp = Utils::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 (empty($child) && $additional) {
             $child[] = $additional;
         }
         foreach ($child as $subSchema) {
             $this->validateChild($value, $subSchema, $key);
         }
     }
 }
Esempio n. 4
0
 public function testScalarFail()
 {
     $container = 6;
     $this->assertEquals(null, Utils::get($container, 'name'));
 }