Example #1
0
 /**
  * @param stdClass $schema
  * @param Uri      $uri
  * @param bool     $inProperties
  *
  * @return stdClass
  */
 private function doResolveReferences(stdClass $schema, Uri $uri, $inProperties = false)
 {
     if ($this->isProcessed($schema, $this->resolvedSchemas)) {
         return $schema;
     }
     $inScope = false;
     if (property_exists($schema, 'id') && is_string($schema->id)) {
         $this->resolver->enter(new Uri($schema->id));
         $inScope = true;
     }
     if (property_exists($schema, '$ref')) {
         $resolved = $this->resolver->resolve($schema);
         $this->resolver->enter($resolved[0], $resolved[1]);
         $schema = $this->doResolveReferences($resolved[1], $resolved[0]);
         $this->resolver->leave();
     } else {
         $version = $this->getVersion($schema);
         foreach ($schema as $property => $value) {
             if ($inProperties || $this->registry->hasKeyword($version, $property)) {
                 if (is_object($value)) {
                     $schema->{$property} = $this->doResolveReferences($value, $uri, $property === 'properties');
                 } elseif (is_array($value)) {
                     foreach ($value as $index => $element) {
                         if (is_object($element)) {
                             $schema->{$property}[$index] = $this->doResolveReferences($element, $uri);
                         }
                     }
                 }
             }
         }
     }
     if ($inScope) {
         $this->resolver->leave();
     }
     return $schema;
 }