Convert model to data transfer object.

@param array $root
@param array $schema
@param array $transformations
@param string $path
@return object
775833
public function toDataTransferObject($root, $schema, $transformations, $path='')
    {
        $dto = new DataTransferObject();

        // get morphed schema
        if($this->morphClass) {
            $morphKey = '...'.Str::studly($this->morphClass);
            if (isset($schema[$morphKey])) {
                $schema = $schema[$morphKey];
            }
        }

        foreach ($schema as $key => $value) {
            // entry is attribute
            if (is_numeric($key)) {
                // transformation key
                $transformationKey = ($path)
                    ? $root.'.'.$path.'.'.$value
                    : $root.'.'.$value;

                // set value
                if ($value == '__type') {
                    $dto->{$value} = class_basename($this->class);
                } elseif (isset($transformations[$transformationKey])) {
                    $node = new GraphNode;
                    $transformations[$transformationKey]($node, $this->attributes);
                    $dto->{$value} = $node->getValue();
                } elseif (isset($transformations['*.'.$value])) {
                    $node = new GraphNode;
                    $transformations['*.'.$value]($node, $this->attributes);
                    $dto->{$value} = $node->getValue();
                } else {
                    $columnName = $this->getColumnName($value);
                    if (isset($this->attributes[$columnName])) {
                        $dto->{$value} = $this->attributes[$columnName];
                    }
                }
            }

            // entry is relation
            if (! is_numeric($key) && isset($this->relations[$key])) {
                // set value and transform childs to dtos
                $newPath = ($path) ? $path.'.'.$key : $key;
                $dto->{$key} = $this->relations[$key]->toDataTransferObject(
                    $root,
                    $value,
                    $transformations,
                    $newPath
                );
            }
        }

        return $dto;
    }
1300954
private function parseRamlData($ramlData, $rootDir)
    {
        if (!isset($ramlData['title'])) {
            throw new RamlParserException();
        }

        $ramlData = $this->parseLibraries($ramlData, $rootDir);

        $ramlData = $this->parseTraits($ramlData);

        $ramlData = $this->parseResourceTypes($ramlData);

        if ($this->configuration->isSchemaParsingEnabled()) {
            if (isset($ramlData['schemas'])) {
                $schemas = [];
                foreach ($ramlData['schemas'] as $schemaCollection) {
                    foreach ($schemaCollection as $schemaName => $schema) {
                        $schemas[$schemaName] = $schema;
                    }
                }
            }
            foreach ($ramlData as $key => $value) {
                if (0 === \strpos($key, '/')) {
                    if (isset($schemas)) {
                        $value = $this->replaceSchemas($value, $schemas);
                    }
                    if (\is_array($value)) {
                        $value = $this->recurseAndParseSchemas($value, $rootDir);
                    }
                    $ramlData[$key] = $value;
                }
            }
        }

        if (isset($ramlData['securitySchemes'])) {
            $ramlData['securitySchemes'] = $this->parseSecuritySettings($ramlData['securitySchemes']);
        }

        return ApiDefinition::createFromArray($ramlData['title'], $ramlData);
    }
1155240
private function recurseAndParseSchemas(array $array, $rootDir)
    {
        foreach ($array as &$value) {
            if (\is_array($value)) {
                if (isset($value['schema'])) {
                    $fileDir = $this->getCachedFilePath($value['schema']);
                    $schema = null;
                    foreach ($this->schemaParsers as $schemaParser) {
                        try {
                            $schemaParser->setSourceUri(
                                'file://' . ($fileDir ? $fileDir : $rootDir . DIRECTORY_SEPARATOR)
                            );
                            $schema = $schemaParser->createSchemaDefinition($value['schema']);

                            break;
                        } catch (\RuntimeException $e) {
                        }
                    }

                    if ($schema === null) {
                        throw new InvalidSchemaFormatException();
                    }

                    $value['schema'] = $schema;
                } else {
                    $value = $this->recurseAndParseSchemas($value, $rootDir);
                }
            }
        }

        return $array;
    }
851487
public static function getSchemaPointers($path, $isURIFragmentId = false)
    {
        $items = explode('->', $path);
        unset($items[0]);
        $result = array();
        $pointer = $isURIFragmentId ? '#' : '';
        foreach ($items as $item) {
            $parts = explode(':', $item);
            if (isset($parts[0])) {
                $schemaPaths = explode('[', $parts[0], 2);
                if (isset($schemaPaths[1])) {
                    $schemaPaths[1] = substr(strtr($schemaPaths[1], array('~1' => '~', '~2' => ':')), 0, -1);
                }

                if ($schemaPaths[0] === Schema::PROP_REF) {
                    $result[] = $pointer . '/' . JsonPointer::escapeSegment(Schema::PROP_REF, $isURIFragmentId);
                    if ($schemaPaths[1][0] !== '#') { // Absolute URI.
                        $pointer = $schemaPaths[1];
                    } else {
                        $pointer = self::rebuildPointer($schemaPaths[1], $isURIFragmentId);
                    }
                    continue;
                }
                $pointer .= '/' . JsonPointer::escapeSegment($schemaPaths[0], $isURIFragmentId);
                if (isset($schemaPaths[1])) {
                    $pointer .= '/' . JsonPointer::escapeSegment($schemaPaths[1], $isURIFragmentId);
                } elseif (isset($parts[1])) {
                    $pointer .= '/' . JsonPointer::escapeSegment($parts[1], $isURIFragmentId);
                }
            }
        }
        if ($pointer === '') {
            $pointer = '/';
        }
        $result[] = $pointer;
        return $result;
    }
810797
public function toAbsolutePath($path, $rootDir)
    {
        if (!is_string($path)) {
            return false;
        }

        if ($this->isRelativePath($path)) {
            return $rootDir . DIRECTORY_SEPARATOR . $path;
        }

        return $path;
    }
948658
public static function create(Path $path, int $from, int $to, array $middleTransitions, array $middleData, array $middlePlaces): Path
    {
        $beginTransitions = [];
        $endTransitions = [];
        $beginData = [];
        $endData = [];
        $beginPlaces = [];
        $endPlaces = [];
        foreach ($path as $index => $step) {
            if ($index <= $from) {
                $beginTransitions[] = $step[0];
                $beginData[] = $step[1];
                $beginPlaces[] = $step[2];
            } elseif ($index > $to) {
                $endTransitions[] = $step[0];
                $endData[] = $step[1];
                $endPlaces[] = $step[2];
            }
        }

        $transitions = array_merge($beginTransitions, $middleTransitions, $endTransitions);
        $data = array_merge($beginData, $middleData, $endData);
        $places = array_merge($beginPlaces, $middlePlaces, $endPlaces);
        $newPath = new Path($transitions, $data, $places);

        return $newPath;
    }
831217
@Override
    public Schema transform(Schema schema) {
        int nCols = schema.numColumns();
        List<ColumnMetaData> meta = schema.getColumnMetaData();
        List<ColumnMetaData> newMeta = new ArrayList<>(nCols);
        newMeta.addAll(meta);
        newMeta.add(new StringMetaData(outputColumnName));
        return schema.newSchema(newMeta);
    }
1336934
@Override
  public Schema convertSchema(Schema inputSchema, WorkUnitState workUnit) throws SchemaConversionException {
    if (this.fieldRemover.isPresent()) {
      return this.fieldRemover.get().removeFields(inputSchema);
    }
    return inputSchema;
  }
660894
public static void transferDirect(Pipe.Schema pipeSchema, Pipe pipe, 
            Input input, Output output) throws IOException
    {
        pipeSchema.transfer(pipe, input, output);
    }
784854
protected function parseRelationsFromSchema(array $schema, $path='')
    {
        $results = [];

        foreach ($schema as $key => $value) {
            if (! is_numeric($key)) {
                // join relation
                if (substr($key, 0, 3) != '...') {
                    $childPath = ($path)
                        ? $path.'.'.$key
                        : $key;
                    $results[$childPath] = (isset($this->constraints[$this->root.'.'.$childPath]))
                        ? $this->constraints[$this->root.'.'.$childPath]
                        : function () {};
                } else {
                    $childPath = $path;
                }

                // recursive call
                $results = array_merge($results, $this->parseRelationsFromSchema($value, $childPath));
            }
        }

        return $results;
    }
1051835
public function JsonToObj($json, $root = False){
        $array = json_decode($json, $assoc = true);
        $obj = $this->ArrayToObj($array);
        return $obj;
    }
924590
public function dumpSchema(Schema $schema, $doFinalInitialization = true)
    {
        $rootNode = $this->document->createElement('app-data');
        $this->document->appendChild($rootNode);
        foreach ($schema->getDatabases($doFinalInitialization) as $database) {
            $this->appendDatabaseNode($database, $rootNode);
        }

        return trim($this->document->saveXML());
    }
592225
@Override
    public Schema transform(Schema inputSchema) {
        Schema.Builder newSchema = new Schema.Builder();
        for (int i = 0; i < inputSchema.numColumns(); i++) {
            if (inputSchema.getType(i) == ColumnType.String) {
                newSchema.addColumnDouble(inputSchema.getMetaData(i).getName());
            } else
                newSchema.addColumn(inputSchema.getMetaData(i));

        }
        return newSchema.build();
    }
518943
public function execute(?string $schemaName = null, array $request, $rootValue = null): ExecutionResult
    {
        $executorArgumentsEvent = $this->preExecute(
            $this->getSchema($schemaName),
            $request[ParserInterface::PARAM_QUERY] ?? null,
            new \ArrayObject(),
            $rootValue,
            $request[ParserInterface::PARAM_VARIABLES],
            $request[ParserInterface::PARAM_OPERATION_NAME] ?? null
        );

        $executorArgumentsEvent->getSchema()->processExtensions();

        $result = $this->executor->execute(
            $executorArgumentsEvent->getSchema(),
            $executorArgumentsEvent->getRequestString(),
            $executorArgumentsEvent->getRootValue(),
            $executorArgumentsEvent->getContextValue(),
            $executorArgumentsEvent->getVariableValue(),
            $executorArgumentsEvent->getOperationName()
        );

        $result = $this->postExecute($result);

        return $result;
    }
636792
function &_subArray(&$root, $path, $create = false)
    {
        $false = false;

        if (!is_array($root)) {
            return $false;
        }

        foreach (explode('/', $path) as $i) {
            if (!is_array($root)) {
                return $false;
            }

            if (!isset($root[$i])) {
                if (!$create) {
                    return $false;
                }

                $root[$i] = array();
            }

            $root = &$root[$i];
        }

        return $root;
    }
677116
protected static function convertFormToModelRepresentation(
        ContainerInterface $container,
        string $schemaClass,
        array $formData
    ): array {
        assert(self::classImplements($schemaClass, SchemaInterface::class));

        /** @var SchemaInterface $schemaClass */
        $modelClass = $schemaClass::MODEL;
        assert(empty($modelClass) === false);

        $attributes = [];

        /** @var ModelSchemaInfoInterface $modelSchemeInfo */
        $modelSchemeInfo = $container->get(ModelSchemaInfoInterface::class);
        foreach ($formData as $jsonName => $value) {
            if ($schemaClass::hasAttributeMapping($jsonName) === true) {
                $modelAttrName              = $schemaClass::getAttributeMapping($jsonName);
                $attributes[$modelAttrName] = $value;
            } elseif ($schemaClass::hasRelationshipMapping($jsonName) === true) {
                $modelRelName        = $schemaClass::getRelationshipMapping($jsonName);
                $fkName              = $modelSchemeInfo->getForeignKey($modelClass, $modelRelName);
                $attributes[$fkName] = $value;
            }
        }

        return $attributes;
    }
658857
public function transformToRelationshipObject(ResourceTransformation $transformation, DataInterface $data): ?array
    {
        if ($transformation->object === null || $transformation->resource === null) {
            return null;
        }

        $relationships = $transformation->resource->getRelationships($transformation->object);
        if (isset($relationships[$transformation->requestedRelationshipName]) === false) {
            throw $transformation->exceptionFactory->createRelationshipNotExistsException($transformation->requestedRelationshipName);
        }

        $defaultRelationships = $transformation->resource->getDefaultIncludedRelationships($transformation->object);

        $transformation->result = $this->transformRelationshipObject(
            $transformation,
            $data,
            $relationships[$transformation->currentRelationshipName],
            $defaultRelationships
        );

        return $transformation->result;
    }