/** * @param string $name * @param string $databaseName * * @return Client */ public function getClient(string $name, string $databaseName = null) : Client { $clientKey = !is_null($databaseName) ? $name . '.' . $databaseName : $name; if (!isset($this->clients[$clientKey])) { $conf = $this->configurations[$name]; $uri = sprintf('mongodb://%s:%d', $conf->getHost(), $conf->getPort()); $options = array_merge(['database' => $databaseName], $conf->getOptions()); $this->clients[$clientKey] = $this->buildClient($uri, $options, []); $this->logger->addConnection($clientKey); } return $this->clients[$clientKey]; }