Esempio n. 1
0
 public function resolveRef($ref)
 {
     $jsonPointer = new JsonPointer($ref);
     $refSchema = $this->getSchema($jsonPointer->getFilename());
     foreach ($jsonPointer->getPropertyPaths() as $path) {
         if (is_object($refSchema) && property_exists($refSchema, $path)) {
             $refSchema = $this->resolveRefSchema($refSchema->{$path});
         } elseif (is_array($refSchema) && array_key_exists($path, $refSchema)) {
             $refSchema = $this->resolveRefSchema($refSchema[$path]);
         } else {
             throw new UnresolvableJsonPointerException(sprintf('File: %s is found, but could not resolve fragment: %s', $jsonPointer->getFilename(), $jsonPointer->getPropertyPathAsString()));
         }
     }
     return $refSchema;
 }
Esempio n. 2
0
 /**
  * @param JsonPointer $pointer
  * @return string property path
  */
 protected function convertJsonPointerIntoPropertyPath(JsonPointer $pointer)
 {
     $result = array_map(function ($path) {
         return sprintf(is_numeric($path) ? '[%d]' : '.%s', $path);
     }, $pointer->getPropertyPaths());
     return trim(implode('', $result), '.');
 }
Esempio n. 3
0
 /**
  * @param JsonPointer $jsonPointer
  * @param object $refSchema
  * @throws UnresolvableJsonPointerException when json schema file is found but reference can not be resolved
  * @return object
  */
 private function getRefSchema(JsonPointer $jsonPointer, $refSchema)
 {
     foreach ($jsonPointer->getPropertyPaths() as $path) {
         if (is_object($refSchema) && property_exists($refSchema, $path)) {
             $refSchema = $refSchema->{$path};
         } elseif (is_array($refSchema) && array_key_exists($path, $refSchema)) {
             $refSchema = $refSchema[$path];
         } else {
             throw new UnresolvableJsonPointerException(sprintf('File: %s is found, but could not resolve fragment: %s', $jsonPointer->getFilename(), $jsonPointer->getPropertyPathAsString()));
         }
     }
     return $refSchema;
 }