Unserialize data collection.

@param  array $collection

@return array
9352
public function unserializeCollection($collection)
    {
        if (is_array($collection)) {
            return array_map(function ($value) {
                return maybe_unserialize(reset($value));
            }, $collection);
        }

        return maybe_unserialize($collection);
    }
1155761
public function transform($collection)
    {
        if (null === $collection) {
            return [];
        }

        if (!$collection instanceof Collection) {
            throw new UnexpectedTypeException($collection, 'Doctrine\Common\Collections\Collection');
        }

        return $collection->toArray();
    }
122619
private function unserializeArray(array $data)
    {
        $unserialized = [];

        foreach ($data as $key => $value) {
            if ($value instanceof ObjectStub) {
                $unserialized[$key] = $value->getObject();

                continue;
            }

            $unserialized[$key] = is_array($value) ? $this->unserializeArray($value) : $value;
        }

        return $unserialized;
    }
1148332
public function persist($collection, array $document)
    {
        

        if ($collection instanceof Collection) {
            $collectionName = $collection->getName();
        } else {
            $collectionName = $collection;
            $collection = static::factory($collection);
        }
        
        $data = $this->marshall($document);
        $result = false;

        
        if (!isset($document['$id'])) {
            $id = $this->insert($collectionName, $data);
            if ($id) {
                $data['$id'] = $id;
                $result = $data;
            }
        } else {
            $data['id'] = $document['$id'];
            unset($data['$id']);
            $result = $this->update($collectionName, $data);

            if ($result) {
                $result = $data;
            }
        }

        return $this->unmarshall($result);
    }
957988
public function desc(array $collection)
    {
        $this->changeDirection(false);
        $collection = $this->asc($collection);
        $this->changeDirection(true);
        return $collection;
    }
1320432
public function unserialize($data)
    {
        $object = unserialize($data);

        $this->resolver = $object['resolver'];
        $this->collection = $object['collection'];
    }
1133092
protected function collection_to_array($collection)
    {
        if ($collection instanceof self) {
            return $collection->toArray();

        } else if ($collection instanceof \Traversable) {
            return iterator_to_array($collection);

        } else if ($collection instanceof Arrayable) {
            return $collection->toArray();

        } else if ($collection instanceof Jsonable) {
            return json_decode($collection->toJson(), true);

        } else if (is_object($collection) || is_array($collection)) {
            return (array)$collection;

        } else {
            throw new \InvalidArgumentException(sprintf(
                '$collection has type %s, which is not collection-like',
                gettype($collection)
            ));
        }
    }
1322205
public function merge(Collection $collection) {
		if ($collection->isEmpty()) {
			return $this;
		}
		
		$primary = $this->getPrimary();
		
		if ($primary !== null) {
			$sourcePrimary = $collection->getPrimary();
		
			if ($primary !== $sourcePrimary) {
				$collection = clone $collection;
				$collection->setPrimary($primary);
			}
		}
		
		$data   = &$collection->getDataLinked();
		$models = $collection->getInstancedModels();
		
		if ($primary === null) {
			$this->_data = array_merge($this->_data, $data);
			
			if (! empty($models)) {
				$this->_models = array_merge($this->_models , $models);
			}
		} else {
			$this->_data = $data + $this->_data;
			
			if (! empty($models)) {
				$this->_models = $models + $this->_models;
			}
		}
		
		$this->_pointer = 0;
		$this->_map     = array_keys($this->_data);
		
		return $this;
	}
1024146
public function toHierarchy($collection): array
    {
        // Trees mapped
        $trees = [];
        if (count($collection) > 0) {
            // Node Stack. Used to help building the hierarchy
            $stack = [];
            foreach ($collection as $item) {
                $item[$this->treeKey] = [];
                // Number of stack items
                $l = count($stack);
                // Check if we're dealing with different levels
                while ($l > 0 && $stack[$l - 1]['level'] >= $item['level']) {
                    array_pop($stack);
                    --$l;
                }
                // Stack is empty (we are inspecting the root)
                if (0 == $l) {
                    // Assigning the root node
                    $i = count($trees);
                    $trees[$i] = $item;
                    $stack[] = &$trees[$i];
                } else {
                    // Add node to parent
                    $i = count($stack[$l - 1][$this->treeKey]);
                    $stack[$l - 1][$this->treeKey][$i] = $item;
                    $stack[] = &$stack[$l - 1][$this->treeKey][$i];
                }
            }
        }

        return $trees;
    }
545289
public function serializeConditionCollection(ConditionCollection $collection)
    {
        if ($collection->count() == 0) {
            /** @var ConditionInterface $conditionNone */
            $conditionNone = $this->container->get(
                'thelia.condition.match_for_everyone'
            );
            $collection[] = $conditionNone;
        }
        $serializableConditions = [];
        /** @var $condition ConditionInterface */
        foreach ($collection as $condition) {
            $serializableConditions[] = $condition->getSerializableCondition();
        }

        return base64_encode(json_encode($serializableConditions));
    }
360797
public function transform($collection)
    {
        if (!$collection instanceof Collection) {
            // If given "collection" is an object we need to wrap it into an array, and pass into collection.
            $collection = new Collection(is_array($collection) ? $collection : [$collection]);
        }

        // If transform is declared or set, we can execute transform on his object.
        if ($this->hasTransformer()) {
            return $this->transform->executeOn($collection);
        }

        // Otherwise, we can return collection without transformation.
        return $collection;
    }
507631
protected function removeEmpty($collection) {
        foreach ($collection as $key => $value) {
            if (empty($value)) {
                unset($collection[$key]);
            }
        }

        return $collection;
    }
1295982
public function unserialize($serialized)
    {
        $attributes = unserialize($serialized);

        $conn = Ioc::make(Pool::class)->getConnection();
        $db = $conn->defaultDatabase;
        $collectionObject = $conn->getRawConnection()->$db->{$attributes['collection']};

        foreach ($attributes as $key => $value) {
            $this->$key = $value;
        }

        $this->collection = $collectionObject;
    }
1035152
public static function toArrayRecursive($collection) {
		$arr = $collection;
		if (is_object($collection) && method_exists($collection, 'toArray')) {
			$arr = $collection->toArray();
		}

		return array_map(function ($v) {
			if (is_object($v) && method_exists($v, 'toArray')) {
				return static::toArrayRecursive($v);
			}
			return $v;
		}, $arr);
	}
1361547
public function bulkSave($collection = [])
    {
        $params = [];

        $defaultIndex = $this->connection->getDefaultIndex();

        foreach ($collection as $item) {
            $modelIndex = $item->getDocumentIndex();

            $params['body'][] = [
                'index' => [
                    '_id'    => $item->getKey(),
                    '_type'  => $item->getDocumentType(),
                    '_index' => $modelIndex ? $modelIndex : $defaultIndex,
                ],
            ];
            $params['body'][] = $item->getDocumentData();
        }

        return $this->connection->bulkStatement($params);
    }
912576
protected function _unserialize($input)
	{
		$data = @unserialize($input);

		if (is_array($data))
		{
			foreach ($data as $key => $val)
			{
				if (is_string($val))
				{
					$data[$key] = str_replace('{{slash}}', '\\', $val);
				}
			}

			return $data;
		}

		elseif ($data === false)
		{
			is_string($input) and $data = array($input);
		}

		return (is_string($data)) ? str_replace('{{slash}}', '\\', $data) : $data;
	}
162764
public function loadCollection(Collections\AbstractCollection $collection)
    {
        $identifiers = $collection->getIdentifiers();
        if (empty($identifiers)) {
            // Nothing to query.
            return [];
        }
        if ($collection instanceof Collections\InverseCollection) {
            $recordSet = $this->retrieveInverseRecords($collection->getOwner()->getType(), $collection->getType(), $collection->getIdentifiers(), $collection->getQueryField());
        } else {
            $recordSet = $this->retrieveRecords($collection->getType(), $collection->getIdentifiers());
        }

        $models = [];
        foreach ($recordSet as $record) {
            if (true === $this->cache->has($record['type'], $record['identifier'])) {
                $models[] = $this->cache->get($record['type'], $record['identifier']);
                continue;
            }
            $models[] = $this->loadModel($collection->getType(), $record);
        }
        return $models;
    }