src/Factory/RepositoryFactory.php
public function getRepository(DocumentManager $documentManager, $modelName, $collectionName, CacheProvider $repositoryCache = null)
    {
        $repIndex = $modelName . $collectionName;
        if (false != ($repository = $this->cache->fetch($repIndex))) {
            return $repository;
        }

        $classMetadata = $this->classMetadataFactory->getMetadataForClass($modelName);

        if (!isset($collectionName)) {
            $collectionName = $classMetadata->getCollection();
        }

        $repositoryClass = $classMetadata->getRepositoryClass();

        if (is_a($repositoryClass, "JPC\MongoDB\ODM\GridFS\Repository", true) && false === strstr($collectionName, ".files")) {
            $bucketName = $collectionName;
            $collectionName .= ".files";
        } else if (is_a($repositoryClass, "JPC\MongoDB\ODM\GridFS\Repository", true) && false !== strstr($collectionName, ".files")) {
            $bucketName = strstr($collectionName, ".files", true);
        }

        $repIndex = $modelName . $collectionName;
        if (false != ($repository = $this->cache->fetch($repIndex))) {
            return $repository;
        }

        $collection = $this->createCollection($documentManager, $classMetadata, $collectionName);

        $hydratorClass = $classMetadata->getHydratorClass();
        if (!isset($hydratorClass)) {
            throw new \Exception($classMetadata->getName() . ' is not a valid model class. Maybe it doesn\'t have a "Document" annotation.');
        }
        $hydrator = new $hydratorClass($this->classMetadataFactory, $classMetadata, $documentManager, $this);

        $queryCaster = new QueryCaster($classMetadata, $this->classMetadataFactory);

        if (isset($bucketName)) {
            $bucket = $documentManager->getDatabase()->selectGridFSBucket(["bucketName" => $bucketName]);

            $repository = new $repositoryClass($documentManager, $collection, $classMetadata, $hydrator, $queryCaster, null, $repositoryCache, $bucket);
        } else {
            $repository = new $repositoryClass($documentManager, $collection, $classMetadata, $hydrator, $queryCaster, null, $repositoryCache);
        }
        $this->cache->save($repIndex, $repository, 120);

        return $repository;
    }
public function getRepository(DocumentManager $documentManager, $modelName, $collectionName, CacheProvider $repositoryCache = null)
    {
        $repIndex = $modelName . $collectionName;
        if (false != ($repository = $this->cache->fetch($repIndex))) {
            return $repository;
        }

        $classMetadata = $this->classMetadataFactory->getMetadataForClass($modelName);

        if (!isset($collectionName)) {
            $collectionName = $classMetadata->getCollection();
        }

        $repositoryClass = $classMetadata->getRepositoryClass();

        if (is_a($repositoryClass, "JPC\MongoDB\ODM\GridFS\Repository", true) && false === strstr($collectionName, ".files")) {
            $bucketName = $collectionName;
            $collectionName .= ".files";
        } else if (is_a($repositoryClass, "JPC\MongoDB\ODM\GridFS\Repository", true) && false !== strstr($collectionName, ".files")) {
            $bucketName = strstr($collectionName, ".files", true);
        }

        $repIndex = $modelName . $collectionName;
        if (false != ($repository = $this->cache->fetch($repIndex))) {
            return $repository;
        }

        $collection = $this->createCollection($documentManager, $classMetadata, $collectionName);

        $hydratorClass = $classMetadata->getHydratorClass();
        if (!isset($hydratorClass)) {
            throw new \Exception($classMetadata->getName() . ' is not a valid model class. Maybe it doesn\'t have a "Document" annotation.');
        }
        $hydrator = new $hydratorClass($this->classMetadataFactory, $classMetadata, $documentManager, $this);

        $queryCaster = new QueryCaster($classMetadata, $this->classMetadataFactory);

        if (isset($bucketName)) {
            $bucket = $documentManager->getDatabase()->selectGridFSBucket(["bucketName" => $bucketName]);

            $repository = new $repositoryClass($documentManager, $collection, $classMetadata, $hydrator, $queryCaster, null, $repositoryCache, $bucket);
        } else {
            $repository = new $repositoryClass($documentManager, $collection, $classMetadata, $hydrator, $queryCaster, null, $repositoryCache);
        }
        $this->cache->save($repIndex, $repository, 120);

        return $repository;
    }
public function getRepository ( DocumentManager $ documentManager , $ modelName , $ collectionName , CacheProvider $ repositoryCache = null ) { $ repIndex = $ modelName . $ collectionName ; if ( false != ( $ repository = $ this -> cache -> fetch ( $ repIndex ) ) ) { return $ repository ; } $ classMetadata = $ this -> classMetadataFactory -> getMetadataForClass ( $ modelName ) ; if ( ! isset ( $ collectionName ) ) { $ collectionName = $ classMetadata -> getCollection ( ) ; } $ repositoryClass = $ classMetadata -> getRepositoryClass ( ) ; if ( is_a ( $ repositoryClass , "JPC\MongoDB\ODM\GridFS\Repository" , true ) && false === strstr ( $ collectionName , ".files" ) ) { $ bucketName = $ collectionName ; $ collectionName .= ".files" ; } else if ( is_a ( $ repositoryClass , "JPC\MongoDB\ODM\GridFS\Repository" , true ) && false !== strstr ( $ collectionName , ".files" ) ) { $ bucketName = strstr ( $ collectionName , ".files" , true ) ; } $ repIndex = $ modelName . $ collectionName ; if ( false != ( $ repository = $ this -> cache -> fetch ( $ repIndex ) ) ) { return $ repository ; } $ collection = $ this -> createCollection ( $ documentManager , $ classMetadata , $ collectionName ) ; $ hydratorClass = $ classMetadata -> getHydratorClass ( ) ; if ( ! isset ( $ hydratorClass ) ) { throw new \ Exception ( $ classMetadata -> getName ( ) . ' is not a valid model class. Maybe it doesn\'t have a "Document" annotation.' ) ; } $ hydrator = new $ hydratorClass ( $ this -> classMetadataFactory , $ classMetadata , $ documentManager , $ this ) ; $ queryCaster = new QueryCaster ( $ classMetadata , $ this -> classMetadataFactory ) ; if ( isset ( $ bucketName ) ) { $ bucket = $ documentManager -> getDatabase ( ) -> selectGridFSBucket ( [ "bucketName" => $ bucketName ] ) ; $ repository = new $ repositoryClass ( $ documentManager , $ collection , $ classMetadata , $ hydrator , $ queryCaster , null , $ repositoryCache , $ bucket ) ; } else { $ repository = new $ repositoryClass ( $ documentManager , $ collection , $ classMetadata , $ hydrator , $ queryCaster , null , $ repositoryCache ) ; } $ this -> cache -> save ( $ repIndex , $ repository , 120 ) ; return $ repository ; }
Get a repository

@param   DocumentManager     $documentManager    Document manager
@param   string              $modelName          Class of the model
@param   string              $collectionName     Name of MongoDB Collection
@param   CacheProvider       $repositoryCache    Cache for the repository
@return  Repository
Get a repository