src/Mapper.php
public function findObject($type, $id)
    {
        $type = $this->getFullType($type);
        if (class_exists($type)) {
            $table = $type::getCollection();
            if (!($id instanceof MongoId) && $id !== null) {
                try {
                    $id = new MongoId($id);
                } catch (MongoException $e) {
                    $id = null;
                }
            }
            $data = $this->cache->fetch("{$table}_{$id}");
            if (!is_array($data)) {
                $data = $this->mongodb->$table->findOne(['_id' => $id]);
                if (is_array($data)) {
                    $this->cache->store("{$table}_{$id}", $data);
                }
            }
            if ($data === null) {
                return null;
            }
            return new $type($data, $this->mongodb->$table, $this->cache);
        }
        return null;
    }
public function findObject($type, $id)
    {
        $type = $this->getFullType($type);
        if (class_exists($type)) {
            $table = $type::getCollection();
            if (!($id instanceof MongoId) && $id !== null) {
                try {
                    $id = new MongoId($id);
                } catch (MongoException $e) {
                    $id = null;
                }
            }
            $data = $this->cache->fetch("{$table}_{$id}");
            if (!is_array($data)) {
                $data = $this->mongodb->$table->findOne(['_id' => $id]);
                if (is_array($data)) {
                    $this->cache->store("{$table}_{$id}", $data);
                }
            }
            if ($data === null) {
                return null;
            }
            return new $type($data, $this->mongodb->$table, $this->cache);
        }
        return null;
    }
public function findObject ( $ type , $ id ) { $ type = $ this -> getFullType ( $ type ) ; if ( class_exists ( $ type ) ) { $ table = $ type :: getCollection ( ) ; if ( ! ( $ id instanceof MongoId ) && $ id !== null ) { try { $ id = new MongoId ( $ id ) ; } catch ( MongoException $ e ) { $ id = null ; } } $ data = $ this -> cache -> fetch ( "{$table}_{$id}" ) ; if ( ! is_array ( $ data ) ) { $ data = $ this -> mongodb -> $ table -> findOne ( [ '_id' => $ id ] ) ; if ( is_array ( $ data ) ) { $ this -> cache -> store ( "{$table}_{$id}" , $ data ) ; } } if ( $ data === null ) { return null ; } return new $ type ( $ data , $ this -> mongodb -> $ table , $ this -> cache ) ; } return null ; }
Find object by it's Mongo ID and return it
@param string $type Name of class of object that should be returned
@param mixed $id ID of document in Mongo collection that holds the object
@return mixed null if document not found, object of type $type otherwise
Find object by it s Mongo ID and return it