Scalr\Tests\Functional\Api\V2\SpecSchema\SpecManager::resolveReferences PHP Method

resolveReferences() protected method

Resolve schema references to object
protected resolveReferences ( array $schema, mixed $specObject = null, mixed $objectName = null ) : DetailsResponse | ListResponse
$schema array segment Api specifications
$specObject mixed optional object schema view
$objectName mixed optional object property name
return Scalr\Tests\Functional\Api\V2\SpecSchema\DataTypes\DetailsResponse | Scalr\Tests\Functional\Api\V2\SpecSchema\DataTypes\ListResponse
    protected function resolveReferences($schema, $specObject = null, $objectName = null)
    {
        $ref = '$ref';
        if (array_key_exists($ref, $schema)) {
            $refPath = explode('/', ltrim($schema[$ref], '#/'));
            unset($schema[$ref]);
            $object = AbstractSpecObject::init($refPath[1]);
            if (is_null($specObject)) {
                $specObject = $object;
            } else {
                $specObject->entity = $object;
                foreach ($schema as $key => $value) {
                    $specObject->{$key} = $value;
                }
            }
            $schema = $this->getPath(...$refPath);
        } else {
            if (is_null($specObject)) {
                $specObject = AbstractSpecObject::init($objectName);
            }
            $object = $specObject;
        }
        if (array_key_exists('items', $schema)) {
            $object->items = $this->resolveReferences($schema['items'], null, $object->getObjectName());
            unset($schema['items']);
        }
        if (array_key_exists('properties', $schema)) {
            foreach ($schema['properties'] as $nameProp => $prop) {
                if (!array_key_exists('type', $prop)) {
                    $prop['type'] = $nameProp;
                }
                $object->{$nameProp} = $this->resolveReferences($prop, new Property($nameProp));
            }
            unset($schema['properties']);
        }
        if (array_key_exists('x-concreteTypes', $schema)) {
            foreach ($schema['x-concreteTypes'] as $prop) {
                $enumObject = $this->resolveReferences($prop);
                $object->concreteTypes[$enumObject->getObjectName()] = $enumObject;
            }
            unset($schema['x-concreteTypes']);
        }
        foreach ($schema as $key => $value) {
            $object->{$key} = $value;
        }
        return $specObject;
    }