Get the mongo client

@return MongoClient
@throws Exceptions\ConnectionError
357820
public function getClient() {
		if ($this->client === null) {
			$connectionString  = $this->getConnectionString();
			$connectionOptions = $this->getConnectionOptions();

			if ($this->_profilerEnabled) {
				$event = $this->getProfiler()->startInfo('Connect: ' . $connectionString);
			}

			$attempts = $this->connectionAttempts;

			do {
				try {
					$this->client = new MongoClient($connectionString, $connectionOptions);
				}
				catch (MongoConnectionException $exception) {
					sleep($this->connectionTimeout);
				}
				catch (Exception $exception) {
					if ($this->_profilerEnabled) {
						$event->stopError();
					}
				}
			} while ($this->client === null && -- $attempts > 0);

			if ($this->client === null) {
				if ($this->_profilerEnabled) {
					$event->stopError();
				}

				if (isset($exception)) {
					throw new Exceptions\ConnectionError('Unable to connect to the database', $exception->getCode(), $exception);
				} else {
					$exception = new Exceptions\ConnectionError('Unable to connect to the database, after ' . $this->connectionAttempts . ' attempts');
				}

				throw $exception;
			}

			if ($this->_profilerEnabled) {
				if (isset($exception)) {
					$event->stopNotice();
				} else {
					$event->stopSuccess();
				}

				$this->putDetailInfoIntoProfiler();
			}
		}

		return $this->client;
	}
236991
public function getHttpClient()
    {
        if (!is_object($this->_httpClient)) {
            $this->_httpClient = new Client([
                'requestConfig' => [
                    'options' => [
                        'timeout' => 30,
                    ]
                ],
                'responseConfig' => [
                    'format' => Client::FORMAT_JSON
                ],
            ]);
        }
        return $this->_httpClient;
    }
1285992
protected function getRandomConnection(): ?Client
    {
        if ($this->pool) {
            return $this->pool[\array_rand($this->pool)];
        }

        if ($this->hosts) {
            $key = \array_rand($this->hosts);
            $connectionID = $this->hosts[$key];
            unset($key);

            return $this->createConnection($connectionID);
        }

        return null;
    }
70739
public function getConnectionString() {
		$connection = new Url('mongodb');
		$connection->setPath($this->dbname);
		
		if ($this->username !== null) {
			$connection->setUsername($this->username);
			
			if ($this->password !== null) {
				$connection->setPassword($this->password);
			}
		}
		
		if (empty($this->hosts)) {
			$connection->setHost($this->defaultHost)
			           ->setPort($this->defaultPort);
			
			return $connection->assemble();
		}
		
		$hosts = array_map([$this, 'assembleHost'], $this->hosts);
		$connection->setHost(implode(',', $hosts));
		
		return $connection->assemble();
	}
1080332
public function getResult()
    {
        $url = $this->buildUrl($this->url);

        try {
            $response = $this->makeRequest($url);

            return $this->prepareResponseResult($response);
        }
        // The client needs to know only one exception, no
        // matter what exception is thrown by Guzzle
         catch (TransferException $e) {
            throw new ConnectionException($e->getMessage());
        }
    }
1353654
function setClient($clientName, MongoDB\Client $clientMongo)
    {
        if ($this->hasClient($clientName))
            throw new \Exception(sprintf('Client with name (%s) already exists and cant be replaced.', $clientName));


        $this->clients[$clientName] = $clientMongo;
        return $this;
    }
1270787
public function getServer() {
        $server = 'mongodb://';

        if ($servers = $this->getConfig('servers')) {
            $server .= implode(',', $servers);

        } else {
            if ($socket = $this->getSocket()) {
                $server .= $socket;
            } else {
                $server .= $this->getHost() . ':' . $this->getPort();
            }
        }

        return $server;
    }
292616
public function getMongoDb($config)
	{
		if( class_exists( 'MongoClient' ) )
		{
			$class = 'MongoClient';
		}
		else
		{
			$class = 'Mongo';
			debug_enforce(
				class_exists( $class ),
				"No 'Mongo' class available. Make sure you've installed php mongo extension correctly."
			);
		}

		$confOptions = array();

		if (!empty($config["mongo_username"])) {
			$confOptions["username"] = $config["mongo_username"];
		}

		if (!empty($config["mongo_password"])) {
			$confOptions["password"] = $config["mongo_password"];
		}

		/** @var $_conn Mongo */
		$_conn = new $class(
			'mongodb://'.$config['mongo_host'],
			$confOptions
		);
		$dbMongo = $_conn->selectDB($config["db_name"]);

		$dbMongo->listCollections();
		return $dbMongo;
	}
802898
public function getGuzzle()
    {

        if ($this->guzzle)
            return $this->guzzle;

        $this->guzzle = new Client();

        return $this->guzzle;

    }
525363
private static function connection()
    {
        if (!self::$connection) {
            self::$connection = new Connection();
            if (self::$client_id) {
                self::$connection->authenticateOauth(self::$client_id, self::$auth_token);
            } else {
                self::$connection->authenticateBasic(self::$username, self::$api_key);
            }
        }

        return self::$connection;
    }
1305225
private function fetchCollection()
    {
        $contextOptions = $this->getContextOptions();

        if (isset($contextOptions[$this->_protocol]['collection'])) {
            $collection = $contextOptions[$this->_protocol]['collection'];
            if ($collection instanceof Collection) {
                throw new InvalidConfigException('"collection" context option should be an instance of "' . Collection::className() . '"');
            }

            return $collection;
        }

        $connection = isset($contextOptions[$this->_protocol]['db'])
            ? $contextOptions[$this->_protocol]['db']
            : 'mongodb';

        /* @var $connection Connection */
        $connection = Instance::ensure($connection, Connection::className());

        list($databaseName, $collectionPrefix) = explode('.', $this->_namespace, 2);
        return $connection->getDatabase($databaseName)->getFileCollection($collectionPrefix);
    }
155707
protected function getQueue()
    {
        if ($this->queue === null) {
            $queue = new \Expose\Queue\Mongo();
            $this->queue = $queue;
        } else {
            $queue = $this->queue;
        }
        return $queue;
    }
904536
private function _getClient(): ClientInterface
    {
        if (! $this->client instanceof ClientInterface) $this->client = new Client($this->clientConfig);
        return $this->client;
    }
816285
private function getClient(): Client
    {
        if (null !== $this->client) {
            return $this->client;
        }

        return $this->client = new Client(
            $this->config['carrier'],
            $this->config['key'],
            $this->config['cache'],
            $this->config['debug']
        );
    }
770648
public static function getHttpClient()
    {
        if(self::$httpClient) {
            return self::$httpClient;
        }
        $client = new Client();
        return self::$httpClient = $client;
    }
232591
public function getClient()
    {
        if (!$this->client) {
            $client = new GuzzleHelper();

            $this->configureClient($client);

            return $this->client = $client->getClient();
        }

        return $this->client;
    }
640432
public function connect(): DriverInterface
    {
        // URL options
        $options = $this->getConfig()->get();

        // TODO: This option should be optional, in addition, it may not be an array
        // Driver options
        $optionsDriver = $options['driver_options']->get();

        try {
            $connection = new MongoManager(
                $this->getDsn(),
                $this->getOptions($options, self::AVAILABLE_OPTIONS),
                $this->getOptions($optionsDriver, self::AVAILABLE_DRIVER_OPTIONS)
            );
            $this->setInstance($connection);

        } catch (RuntimeException $e) {
            new Exception('Unable to connect');
        } catch (InvalidArgumentException $e) {
            new Exception('Invalid argument provided');
        }

        return $this;
    }