On pre handle request with collection.

@param Collection $collection The collection.
@return Collection Returns the cloned collection.
495194
public function onPreHandleRequestWithCollection(Collection $collection) {
        $output = new ArrayCollection();
        foreach ($collection as $current) {
            $output->add($current);
        }
        return $output;
    }
1061748
public function getCollection($collectionName) {
		if (! isset($this->collections[$collectionName])) {
			$this->collections[$collectionName] = $this->getDatabase()->selectCollection($collectionName);
		}

		return $this->collections[$collectionName];
	}
160331
public function load($collection)
    {
        $collectionId = $this->getCollectionId($collection);

        if ($this->isValidCollectionId($collectionId)) {
            throw new ClientException('Cannot alter a collection without a collection id');
        }

        $result = $this->getConnection()->put(
            UrlHelper::buildUrl(Urls::URL_COLLECTION, [$collectionId, self::OPTION_LOAD]),
            ''
        );

        return $result;
    }
1135369
public function collection(Collection $collection)
    {
        $entries = new Entries();

        foreach ($collection as $group) {
            $entry = new Entry($group);

            $entry
                ->conditionalField('id', function () {
                    return Subbly::api('subbly.user')->hasAccess('subbly.backend.auth');
                })

                ->field('name')
                ->field('permissions')

                ->dateField('created_at')
                ->dateField('updated_at')
            ;

            $entries->addEntry($entry);
        }

        return $entries->toArray();
    }
507631
protected function removeEmpty($collection) {
        foreach ($collection as $key => $value) {
            if (empty($value)) {
                unset($collection[$key]);
            }
        }

        return $collection;
    }
1000775
public function collectionAction($collection, Request $request = null)
    {
        $action = $this->container->get(CollectionPostArchiveAction::class);

        return $action($this->resolveRequest($request), $collection);
    }
45724
public function setCollection(array $collection)
    {
        if (is_array($this->buildItems) 
                && array_key_exists('collection', $this->buildItems) 
                && !empty($this->buildItems['collection'])) {
            unset($this->collection);
        }
        $this->setBuildItems();
        foreach ($collection as $builder) {
            $this->addBuilder($builder);
        }
        
        return $this;
    }
691959
public function getCollectionId($collection)
    {
        if ($collection instanceof Collection) {
            $collectionId = $collection->getId();

            return $collectionId;
        }

        $collectionId = $collection;

        return $collectionId;
    }
565590
public function get($collection)
    {
        $collection = $this->makeCollection($collection);

        $url      = UrlHelper::buildUrl(Urls::URL_COLLECTION, [$collection]);
        $response = $this->getConnection()->get($url);

        $data = $response->getJson();

        return Collection::createFromArray($data);
    }
744416
public function make($collection)
    {
        $collection = $this->getCollectionNameFromInstance($collection);

        $this->dirty = true;
        
        return $this->get($collection) ?: $this->entries[$collection] = new Entry;
    }
28827
public static function addCollection($collection)
  {
    static::checkConnexion();
    $r = self::$db->createCollection($collection);
    if (gettype($r) == 'object' && get_class($r) == 'MongoCollection') {
      return true;
    }
    return false;
  }
566964
public function newObject($collection)
    {
        /** @var MongoObject $obj */
        $obj =$this->container->get($this->classMap->getClassForResult($collection, []));
        $obj->setCollection($collection);

        return $obj;
    }
190821
public function updateMany(): Collection
	{
		$collection = new Collection();

		foreach ($this->getInput() as $item) {
			$repository = clone $this;
			$repository->setInput($item);
			$collection->add($repository->update($repository->getInputId()));
		}

		return $collection;
	}
617094
public function intersect($collection)
    {
        $intersection = new DefaultCollection();
        /** @var ModelInterface $localModel */
        foreach ($this as $localModel) {
            /** @var ModelInterface $otherModel */
            foreach ($collection as $otherModel) {
                if (($localModel->getProviderName() === $otherModel->getProviderName())
                    && ($localModel->getId() === $otherModel->getId())
                ) {
                    $intersection->push($localModel);
                }
            }
        }

        return $intersection;
    }
791879
public function collection(Collection $collection)
    {
        $entries = new Entries();

        foreach ($collection as $user) {
            $entry = new Entry($user);

            $entry
                ->conditionalField('id', function () {
                    return Subbly::api('subbly.user')->hasAccess('subbly.backend.auth');
                })

                ->field('uid')
                ->field('email')
                ->field('firstname')
                ->field('lastname')
                ->compositeField('displayName', 'firstname', 'lastname')

                ->relationshipField('addresses', 'Subbly\\Presenter\\V1\\UserAddressPresenter')
                ->integer('orders_total', $user->countOrders())
                ->relationshipField('orders', 'Subbly\\Presenter\\V1\\OrderPresenter')
                ->relationshipField('groups', 'Subbly\\Presenter\\V1\\GroupPresenter')

                ->dateField('created_at')
                ->dateField('updated_at')
            ;

            $entries->addEntry($entry);
        }

        return $entries->toArray();
    }
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;
    }
1080582
public static function addLocaleToCollection(Collection $collection, LocaleInterface $locale)
    {
        $exist = $collection->exists(function ($key, LocaleInterface $el) use ($locale) {
            return $el->isLocale($locale->getLocale());
        });
        if (!$exist) {
            $collection->add($locale);
        }

        return $collection;
    }