Registers every entity in collection to the repository identity map

@param EntityCollection $collection

@return self
543929
protected function updateIdentityMap(EntityCollection $collection)
    {
        if ($collection->isEmpty()) {
            return $this;
        }

        foreach ($collection as $entity)
        {
            $this->repository->getIdentityMap()->set($entity);
        }
        return $this;
    }
586603
public function addCollection(self $collection)
    {
        $this->requirements = array_merge($this->requirements, $collection->all());
    }
84820
public function createReferenceManyInverseSideQuery(PersistentCollection $collection)
    {
        $hints = $collection->getHints();
        $mapping = $collection->getMapping();
        $owner = $collection->getOwner();
        $ownerClass = $this->dm->getClassMetadata(get_class($owner));
        $targetClass = $this->dm->getClassMetadata($mapping['targetDocument']);
        $mappedByMapping = isset($targetClass->fieldMappings[$mapping['mappedBy']]) ? $targetClass->fieldMappings[$mapping['mappedBy']] : array();
        $mappedByFieldName = isset($mappedByMapping['simple']) && $mappedByMapping['simple'] ? $mapping['mappedBy'] : $mapping['mappedBy'] . '.$id';
        $criteria = $this->cm->merge(
            array($mappedByFieldName => $ownerClass->getIdentifierObject($owner)),
            $this->dm->getFilterCollection()->getFilterCriteria($targetClass),
            isset($mapping['criteria']) ? $mapping['criteria'] : array()
        );
        $criteria = $this->uow->getDocumentPersister($mapping['targetDocument'])->prepareQueryOrNewObj($criteria);
        $qb = $this->dm->createQueryBuilder($mapping['targetDocument'])
            ->setQueryArray($criteria);

        if (isset($mapping['sort'])) {
            $qb->sort($mapping['sort']);
        }
        if (isset($mapping['limit'])) {
            $qb->limit($mapping['limit']);
        }
        if (isset($mapping['skip'])) {
            $qb->skip($mapping['skip']);
        }
        if ( ! empty($hints[Query::HINT_SLAVE_OKAY])) {
            $qb->slaveOkay(true);
        }
        if ( ! empty($hints[Query::HINT_READ_PREFERENCE])) {
            $qb->setReadPreference($hints[Query::HINT_READ_PREFERENCE], $hints[Query::HINT_READ_PREFERENCE_TAGS]);
        }

        return $qb->getQuery();
    }
94985
public function schemaCollection(SchemaCollection $collection = null)
    {
        deprecationWarning(
            'Connection::schemaCollection() is deprecated. ' .
            'Use Connection::setSchemaCollection()/getSchemaCollection() instead.'
        );
        if ($collection !== null) {
            $this->setSchemaCollection($collection);
        }

        return $this->getSchemaCollection();
    }
84654
private function registerDataCollector(ContainerBuilder $container): self
    {
        $container->register('contentful.delivery.data_collector', ClientDataCollector::class)
            ->addArgument(new TaggedIteratorArgument('contentful.delivery.client'))
            ->addArgument(new Parameter('contentful.delivery.clients.info'))
            ->addTag('data_collector', [
                'id' => 'contentful.delivery',
                'template' => '@Contentful/Collector/contentful.html.twig',
                'priority' => '250',
            ])
        ;

        return $this;
    }
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;
    }
613543
private function mergeCollectionSqlSelectWithAnotherCollection(EntityRepository $collection): self
    {
        $select_fields = $collection->getSelectFields();
        foreach ($select_fields as $select_field) {
            $this->sql_select_fields[] = $select_field;
        }

        $where_fields = $collection->getWhereFields();
        foreach ($where_fields as $where_field) {
            $this->sql_where_fields[] = $where_field;
        }

        $group_fields = $collection->getGroupByField();
        foreach ($group_fields as $group_field) {
            $this->group_by_fields[] = $group_field;
        }

        $having_fields = $collection->getHavingFields();
        foreach ($having_fields as $having_field) {
            $this->having_fields[] = $having_field;
        }

        $order_fields = $collection->getOrderFields();
        foreach ($order_fields as $order_field) {
            $this->order_fields[] = $order_field;
        }

        $translation_fields = $collection->getTranslationFields();
        foreach ($translation_fields as $translation_field) {
            $this->translation_fields[] = $translation_field;
        }

        $join_tables = $collection->getJoinTables();
        foreach ($join_tables as $join_table) {
            $this->addJoinTable([$join_table['table'], $join_table['alias']], $join_table['left'], $join_table['right'], $join_table['type'], $join_table['right_table']);
        }

        return $this;
    }
1097010
public function set(RelationshipInterface $relationship): RelationshipCollectionInterface
    {
        $this->collection[$relationship->name()] = $relationship;

        return $this;
    }
141832
public function transform($collection)
    {
        if ($collection && !is_array($collection) && !($collection instanceof \ArrayAccess)) {
            // in case of single entity, we have to make sure it's managed
            if (!$this->er->getManager()->contains($collection)) {
                $collection = $this->er->getManager()->merge($collection);
            }
        }
        return $collection;
    }
59227
private function initTemplateEntities(): self
    {
        if (null !== $this->templateEntities) {
            return $this;
        }
        $this->templateEntities = new ArrayCollection();

        return $this;
    }
1058270
private function createReferenceManyWithRepositoryMethodIterator(PersistentCollectionInterface $collection)
    {
        $mapping          = $collection->getMapping();
        $repositoryMethod = $mapping->repositoryMethod;
        $repository       = $this->dm->getRepository($mapping->targetDocument);
        $iterator         = $repository->$repositoryMethod($collection->getOwner());

        if (!$iterator instanceof Iterator) {
            throw new \BadMethodCallException(sprintf('Expected repository method %s to return an iterable object', $repositoryMethod));
        }

        if (!empty($mapping->prime)) {
            $referencePrimer = new ReferencePrimer($this->dm, $this->dm->getUnitOfWork());
            $primers         = array_combine($mapping->prime, array_fill(0, count($mapping->prime), true));
            $class           = $this->dm->getClassMetadata($mapping['targetDocument']);

            $iterator = new PrimingIterator(
                $iterator,
                $class,
                $referencePrimer,
                $primers,
                $collection->isReadOnly()
            );
        }

        return $iterator;
    }
1113757
public function executeOn(Collection $collection)
    {
        if (empty($collection) || $collection->first() === null) {
            return $collection;
        }

        $transformer = $this->repository->transformer;

        if (!(new \ReflectionClass($transformer))->implementsInterface(TransformerInterface::class)) {
            throw new InvalidTransformer();
        }

        /** @var TransformerInterface $transformer */
        $transformer = new $transformer($collection);

        return $transformer->execute();
    }
601070
protected function registerCollections(array $collections)
    {
        $debugger = $this->app->make(Debugger::class);

        foreach ($collections as $collection) {
            $debugger->populateWith($this->app->make($collection));
        }
    }
1224695
public function collection(Collection $collection)
    {
        $entries = new Entries();

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

            $entry
                ->field('id')
                ->field('label')
                ->field('slug')
                ->field('parent')
                ->field('position')
            ;

            $entries->addEntry($entry);
        }

        return $entries->toArray();
    }
300548
public function addCollection(self $collection)
    {
        // we need to remove all routes with the same names first because just replacing them
        // would not place the new route at the end of the merged array
        foreach ($collection->all() as $name => $route) {
            unset($this->routes[$name]);
            $this->routes[$name] = $route;
        }

        foreach ($collection->getResources() as $resource) {
            $this->addResource($resource);
        }
    }
325828
public function withCollection($collection, $transformer = null, $resourceKey = null)
    {
        return $this->respond(
            $this->getCollection($collection, $transformer, $resourceKey)
        );
    }
372068
public function mergeWithCollection(EntityRepository $collection, $join_on_key, $join_index = 'id', $join_type = 'INNER'): self
    {
        $this->addJoinTable($collection->getDbTableName(), $join_index, $join_on_key, $join_type);
        $this->mergeCollectionSqlSelectWithAnotherCollection($collection);

        return $this;
    }