Convert many CouchDb documents to Chill Document objects.

@param array $docs Documents to convert.
@return \Chill\Document[]
164226
protected function toDocuments(array $docs = array())
    {
        if (isset($docs['rows'])) {
            $rtn = array();

            foreach ($docs['rows'] as $row) {
                $rtn[] = $this->toDocument($row['value']);
            }

            return $rtn;
        } else {
            return array();
        }
    }
510787
private function buildAggregateAsObject($document)
    {
        $returnObject = [];

        foreach ($document as $event) {
            $returnObject[] = new Event(
                new AggregateUuid($event->uuid),
                $event->type,
                unserialize($event->body),
                $event->version,
                $event->occurred_on
            );
        }

        return $returnObject;
    }
148596
public function applyTransformations(array $transforms)
    {
        foreach ($this->documents as $doc) {
            foreach ($transforms as $transform) {
                $doc->applyTransformation($transform);
            }
        }
    }
450446
public function getDocumentTypesDto(
        $entities = 'SHOP'
    ) {
        $this->restClient->getConfig()->setPath(
            'request.options/headers/Authorization',
            $this->operatorKey
        );

        $command = $this->restClient->getCommand(
            'DocumentTypesDto',
            array(
                'entities' => $entities,
            )
        );
        $result = $this->restClient->execute($command);

        return $result['documents'];
    }
871340
public function transform($relations = false)
    {
        $relations = $relations ? Config::get('larasearch.paths.' . get_class($this)) : [];

        $doc = $this->load($relations)->toArray();

        return $doc;
    }
992203
public function normalize(MethodDoc $doc) : array
    {
        $docDescription = $docTags = $paramsSchema = $responseSchema = [];

        if (null !== $doc->getDescription()) {
            $docDescription['description'] = $doc->getDescription();
        }
        if (count($doc->getTagList())) {
            $docTags['tags'] = $doc->getTagList();
        }
        if (null !== $doc->getParamsDoc()) {
            $paramsSchema = [
                'params' => $this->typeDocNormalizer->normalize($doc->getParamsDoc())
            ];
        }
        // Create custom result schema only if provided
        if (null !== $doc->getResultDoc()) {
            $responseSchema['result'] = $this->typeDocNormalizer->normalize($doc->getResultDoc());
        }


        return [
            'identifier' => $doc->getIdentifier(),
            'name' =>$doc->getMethodName(),
        ]
            + $docDescription
            + $docTags
            + $paramsSchema
            + $responseSchema
            + $this->appendErrorsSchema($doc)
        ;
    }
1126674
public static function bulkInsert($documents)
    {
        $instance = new static();

        $autoIncrementField = $instance->getAutoIncrementField();
        $allowNull = $instance->isAllowNullValue();
        $fieldTypes = $instance->getFieldTypes();
        foreach ($documents as $i => $document) {
            if ($autoIncrementField && !isset($document[$autoIncrementField])) {
                $document[$autoIncrementField] = $instance->getNextAutoIncrementId();
            }
            foreach ((array)$fieldTypes as $field => $type) {
                if (isset($document[$field])) {
                    $document[$field] = $instance->normalizeValue($type, $document[$field]);
                } elseif ($field !== '_id') {
                    $document[$field] = $allowNull ? null : $instance->normalizeValue($type, '');
                }
            }
            $documents[$i] = $document;
        }

        return $instance->getConnection()->bulkInsert($instance->getSource(), $documents);
    }
962859
public function normalize(HttpServerDoc $doc)
    {
        return [
                'openapi' => '3.0.0',
            ]
            + $this->infoArray($doc)
            + $this->serverArray($doc)
            + $this->tagsArray($doc)
            + $this->pathsArray($doc)
            + $this->externalSchemaListArray($doc);
    }
760458
public function getDocumentActualData($document)
    {
        $class      = $this->dm->getClassMetadata(get_class($document));
        $actualData = [];

        foreach ($class->propertyMetadata as $name => $mapping) {
            // skip not saved attributes
            if ($mapping->notSaved) {
                continue;
            }

            $value = $mapping->getValue($document);

            if ($mapping->isMany() && $value !== null && !($value instanceof PersistentCollectionInterface)) {
                // If $actualData[$name] is not a Collection then use an ArrayCollection.
                if (!$value instanceof Collection) {
                    $value = new ArrayCollection($value);
                }

                // Inject PersistentCollection
                $coll = $this->dm->getConfiguration()->getPersistentCollectionFactory()->create($this->dm, $mapping, $value);
                $coll->setOwner($document, $mapping);
                $coll->setDirty(!$value->isEmpty());
                $mapping->setValue($document, $coll);
                $actualData[$name] = $coll;
            } else {
                $actualData[$name] = $value;
            }
        }

        return $actualData;
    }
523163
protected function convertDirectives(DocumentAST $document): Collection
    {
        return $document->directiveDefinitions()
            ->map(function (DirectiveDefinitionNode $directive) {
                return new Directive([
                    'name' => $directive->name->value,
                    'description' => data_get($directive->description, 'value'),
                    'locations' => (new Collection($directive->locations))
                        ->map(function ($location) {
                            return $location->value;
                        })
                        ->toArray(),
                    'args' => (new Collection($directive->arguments))
                        ->map(function (InputValueDefinitionNode $argument) {
                            $fieldArgumentConfig = [
                                'name' => $argument->name->value,
                                'description' => data_get($argument->description, 'value'),
                                'type' => $this->definitionNodeConverter->toType($argument->type),
                            ];

                            if ($defaultValue = $argument->defaultValue) {
                                $fieldArgumentConfig += [
                                    'defaultValue' => $defaultValue,
                                ];
                            }

                            return new FieldArgument($fieldArgumentConfig);
                        })
                        ->toArray(),
                    'astNode' => $directive,
                ]);
            });
    }
459432
public function insertMany(array $documents)
    {
        foreach ($documents as $document) {
            $this->writeModels[] = [BulkWrite::INSERT_ONE => [$document]];
        }

        return $this;
    }
463827
protected function getMethodsExternalSchemaList(ServerDoc $doc) : array
    {
        $list = [];
        foreach ($doc->getMethodList() as $method) {
            // Merge extra definitions
            $list = array_merge($list, $this->getMethodExternalSchemaList($method));
        }

        return $list;
    }
879337
protected function normalizeAsArray($objects) : array
    {
        $key = $this->relation;

        if (!is_array($objects) && !$objects instanceof Collection) {
            throw new MappingException("column '$key' should be of type array or collection");
        }

        if ($objects instanceof Collection) {
            $objects = $objects->all();
        }

        $normalizedObjects = [];

        foreach ($objects as $object) {
            $wrapper = $this->factory->make($object);
            $normalizedObjects[] = $wrapper->getEntityAttributes();
        }

        if ($this->asJson) {
            $normalizedObjects = json_encode($normalizedObjects);
        }

        return [$key => $normalizedObjects];
    }
1222802
private function getQueryForDocument(object $document) : array
    {
        $id = $this->uow->getDocumentIdentifier($document);
        $id = $this->class->getDatabaseIdentifierValue($id);

        $shardKeyQueryPart = $this->getShardKeyQuery($document);
        return array_merge(['_id' => $id], $shardKeyQueryPart);
    }
733879
public function normalize(HttpServerDoc $doc) : array
    {
        $normalizedDoc = $this->serverDocNormalizer->normalize($doc);

        // Append http infos
        $httpDoc = [];
        if (null !== $doc->getHost()) {
            $httpDoc['host'] = $doc->getHost();
        }
        if (null !== $doc->getBasePath()) {
            $httpDoc['base-path'] = $doc->getBasePath();
        }
        if (count($doc->getSchemeList())) {
            $httpDoc['schemes'] = $doc->getSchemeList();
        }
        if (count($httpDoc)) {
            $normalizedDoc['http'] = $httpDoc;
        }

        return $normalizedDoc;
    }
986621
protected function _inferFieldTypes($docs)
    {
        $fieldTypes = [];
        foreach ($docs as $doc) {
            foreach ($doc as $field => $value) {
                $fieldTypes[$field][gettype($value)] = 1;
            }
        }

        $r = [];
        foreach ($fieldTypes as $field => $types) {
            unset($types['NULL']);
            if (isset($types['object'])) {
                $r[$field] = 'objectid';
            } else {
                if (count($types) !== 1) {
                    ksort($types);
                }
                $r[$field] = implode('|', array_keys($types));
            }
        }

        return $r;
    }
366822
private function getFieldNames(Document $document)
    {
        $result = [];
        foreach ($document->getFields() as $field) {
            $result[$field->getFieldName()] = $field->getExposedName();
        }
        return $result;
    }