Fetch object using MongoDBRef
@param string $typeName name of class of object to fetch (will be
preprended with $this->_modelsNamespace)
@param array $dbref array holding Mongo DBRef reference to object
@return mixed object or null if fetching failed
185556
protected function fetchDBRef($typeName, $dbref)
    {
        $typeName = $this->getFullType($typeName);
        if (class_exists($typeName) && MongoDBRef::isRef($dbref)) {
            $collectionName = $typeName::getCollection();
            $collection = $this->_collection->db->$collectionName;
            $data = $this->_cache->fetch("{$collectionName}_{$dbref['$id']}");
            if ($data === null) {
                $data = $this->_collection->getDBRef($dbref);
            }
            if ($data === null) {
                return null;
            }
            return new $typeName($data, $collection, $this->_cache);
        }
        return null;
    }
643635
protected function definitionsByType(string $typeClassName): Collection
    {
        return $this->definitionMap
            ->filter(function (Node $node) use ($typeClassName) {
                return $node instanceof $typeClassName;
            });
    }
869607
public function create(string $className, string $typeName): Type
    {
        $type = new InputObjectType([
            'name' => $typeName,
            'description' => 'Type to specify join tables in a filter',
            'fields' => function () use ($className): array {
                return $this->getJoinsFields($className);
            },
        ]);

        return $type;
    }
69383
public function fetchAll($namespace, $filter = [], $options = [], $secondaryPreferred = true)
    {
        if (is_bool($secondaryPreferred)) {
            $readPreference = new ReadPreference($secondaryPreferred ? ReadPreference::RP_SECONDARY_PREFERRED : ReadPreference::RP_PRIMARY);
        } else {
            $readPreference = new ReadPreference($secondaryPreferred);
        }
        try {
            $result = $this->_fetchAll($namespace, $filter, $options, $readPreference);
        } catch (\Exception $exception) {
            $result = null;
            $failed = true;
            if (!$this->_ping()) {
                try {
                    $this->close();
                    $result = $this->_fetchAll($namespace, $filter, $options, $readPreference);
                    $failed = false;
                } catch (\Exception $exception) {
                }
            }

            if ($failed) {
                throw new MongodbException($exception->getMessage(), $exception->getCode(), $exception);
            }
        }

        return $result;
    }
1054270
protected function get($objectName, $datas = null)
	{
		if(isset($this->bag[$objectName]))
		{
			return $this->bag[$objectName];
		}

		if($this->cacheDriver)
		{
			if(($cached = $this->cacheDriver->fetch($objectName . $this->cacheSalt)) !== false)
			{
				$this->bag[$objectName] = $cached;
			}
			else
			{
				$this->load($objectName, $datas);
				$this->cacheDriver->save(
						$objectName . $this->getCacheSalt(), $this->bag[$objectName]
				);
			}
		}
		else
		{
			$this->load($objectName, $datas);
		}

		return $this->bag[$objectName];
	}
235189
public static function values($typeName)
    {
        $db = static::getDb();

        return $db->createCommand(
            'SELECT unnest(enum_range(NULL::' . $db->quoteColumnName($typeName) . '))'
        )->queryColumn();
    }
1020225
public function fetchObject($name='stdClass', $ctor_args=null)
    {
        try {
            $data = $this->fetch(\PDO::FETCH_ASSOC);
            return $this->_createObjectFromData($name, $data);
        } catch (\Exception $e) {
            return null;
        }
    }
1332095
public function getDocumentDatabase(string $className) : Database
    {
        $className = $this->classNameResolver->getRealClass($className);

        if (isset($this->documentDatabases[$className])) {
            return $this->documentDatabases[$className];
        }

        $metadata = $this->metadataFactory->getMetadataFor($className);
        assert($metadata instanceof ClassMetadata);

        $db                                  = $metadata->getDatabase();
        $db                                  = $db ?: $this->config->getDefaultDB();
        $db                                  = $db ?: 'doctrine';
        $this->documentDatabases[$className] = $this->client->selectDatabase($db);

        return $this->documentDatabases[$className];
    }
791410
public static function convertToDb($value)
    {
        return $value instanceof ExtReference ?
            \MongoDBRef::create($value->getRef(), $value->getId()) :
            null;
    }
1098929
public function fetchObject(string $className = "stdClass", array $ctorArgs = null)
    {
        $object = BeanFactory::newInstance($className);
        foreach($this->fetch(\PDO::FETCH_ASSOC) as $name => $value)
        {
            $object->$name = $value;
        }
        return $object;
    }
581012
public function fetchAllObject(string $className = 'stdClass', array $constructorArgs = []):  ? array
    {
        $r = $this->DriverStatement->fetchAll(PDO::FETCH_CLASS, $className, $constructorArgs);
        return $r ?: null;
    }
804129
protected static function fetchGedcomRecord(string $xref, int $tree_id): ?string
    {
        // We don't know what type of object this is. Try each one in turn.
        $data = Individual::fetchGedcomRecord($xref, $tree_id);
        if ($data !== null) {
            return $data;
        }
        $data = Family::fetchGedcomRecord($xref, $tree_id);
        if ($data !== null) {
            return $data;
        }
        $data = Source::fetchGedcomRecord($xref, $tree_id);
        if ($data !== null) {
            return $data;
        }
        $data = Repository::fetchGedcomRecord($xref, $tree_id);
        if ($data !== null) {
            return $data;
        }
        $data = Media::fetchGedcomRecord($xref, $tree_id);
        if ($data !== null) {
            return $data;
        }
        $data = Note::fetchGedcomRecord($xref, $tree_id);
        if ($data !== null) {
            return $data;
        }

        // Some other type of record...
        return DB::table('other')
            ->where('o_file', '=', $tree_id)
            ->where('o_id', '=', $xref)
            ->value('o_gedcom');
    }
8335
public function getByRef($sRef, $aData = [])
    {
        if (empty($aData['where'])) {
            $aData['where'] = [];
        }

        $aData['where'][] = [$this->sTableAlias . '.ref', $sRef];

        $aEmails = $this->getAll(null, null, $aData);

        return !empty($aEmails) ? reset($aEmails) : false;
    }
538127
public function fetch($return = self::RETURN_COLLECTION) {
        /** We replace Post.xx by post.xx */
        foreach ($this->_entities as $entity) {
            $class = $this->_getTableEntity($entity);

            if ($entity != $class->name()) {
                $this->_query = preg_replace('#(.*)' . $entity . '\.(.*)#isU', '$1' . $class->name() . '.$2', $this->_query);
            }
        }

        /** Query execution */
        $sql = new Sql();
        $sql->vars($this->_vars);
        $sql->query('orm-' . $this->_token, $this->_query);

        if ($this->_type == self::QUERY_COUNT) {
            return $sql->fetch('orm-' . $this->_token, Sql::PARAM_FETCHCOLUMN);
        }
        else {
            $sql->fetch('orm-' . $this->_token, Sql::PARAM_FETCH);
        }

        $collection = $sql->data($this->_getEntityName($this->_entity->name()));

        /** We can do SELECT OR SELECT DISTINCT OR SELECT RAW */
        if (in_array($this->_type, [self::QUERY_DISTINCT, self::QUERY_RAW])) {
            $nLines = $collection->count();
            $in = '';

            /** @var $value \Gcs\Framework\Core\Orm\Entity\Entity */
            foreach ($collection as $key => $value) {
                $in .= $value->fields()[$value->primary()]->value;

                if ($key < $nLines - 1) {
                    $in .= ', ';
                }
            }

            $builder = new Builder($this->_entity);
            $collection = $builder->find()->where($this->_entity->name() . '.' . $this->_entity->primary() . ' IN (' . $in . ')')->fetch();
        }

        /** If we have fields with a relation ONE TO MANY OR MANY TO MANY */
        foreach ($this->_entity->fields() as $field) {
            if ($field->foreign != null && in_array($field->foreign->type(), [ForeignKey::ONE_TO_MANY, ForeignKey::MANY_TO_MANY])) {
                /** we loop through the results to add each time */
                switch ($field->foreign->type()) {
                    case ForeignKey::ONE_TO_MANY :
                        $collection = $this->_dataOneToMany($field, $collection);
                        break;

                    case ForeignKey::MANY_TO_MANY :
                        $collection = $this->_dataManyToMany($field, $collection);
                        break;
                }
            }
        }

        if ($return == self::RETURN_ENTITY && $collection->count() <= 1) {
            return $collection->first();
        }
        else {
            return $collection;
        }
    }
1214823
public function get(string $typeName) : TypeSchema
    {
        if (!array_key_exists($typeName, $this->types)) {
            throw NotFoundException::model($typeName);
        }

        return $this->types[$typeName];
    }
977999
private function getCollection($type) {
        if ($this->collections[$type] === null) {
            try {
                $this->collections[$type] = $this->getMongoClient()->selectCollection(
                    $this->params['databaseName'],
                    $type
                );
            } catch (MongoException $e) {
                throw new DatabaseException('Could not select collection', 500, $e);
            }
        }

        return $this->collections[$type];
    }
1193426
public function getCollections($databaseName = null) {
		$database = $this->getDatabase($databaseName);

		if ($this->_profilerEnabled) {
			$event = $this->getProfiler()->startRead('Collections list');
		}

		$collections = $database->getCollectionNames();

		if ($this->_profilerEnabled) {
			$event->stopSuccess();
		}

		return $collections;
	}