/** * @param PersistentCollectionInterface $collection * * @return CursorInterface */ public function createReferenceManyWithRepositoryMethodCursor(PersistentCollectionInterface $collection) { $hints = $collection->getHints(); $mapping = $collection->getMapping(); $repositoryMethod = $mapping['repositoryMethod']; $cursor = $this->dm->getRepository($mapping['targetDocument'])->{$repositoryMethod}($collection->getOwner()); if (!$cursor instanceof CursorInterface) { throw new \BadMethodCallException("Expected repository method {$repositoryMethod} to return a CursorInterface"); } if (isset($mapping['sort'])) { $cursor->sort($mapping['sort']); } if (isset($mapping['limit'])) { $cursor->limit($mapping['limit']); } if (isset($mapping['skip'])) { $cursor->skip($mapping['skip']); } if (!empty($hints[Query::HINT_SLAVE_OKAY])) { $cursor->slaveOkay(true); } if (!empty($hints[Query::HINT_READ_PREFERENCE])) { $cursor->setReadPreference($hints[Query::HINT_READ_PREFERENCE], $hints[Query::HINT_READ_PREFERENCE_TAGS]); } return $cursor; }