_client = new Client($config['uri'] ?? 'mongodb://localhost:27017'); $this->_database = $config['database'] ?? ''; } /** * @return Client */ public function client(): Client { return $this->_client; } /** * @param string|null $name null — имя БД из конфига * @return Database */ public function database(?string $name = null): Database { return $this->_client->selectDatabase($name ?? $this->_database); } /** * @param string $name Имя коллекции * @param string|null $database null — имя БД из конфига * @return Collection */ public function collection(string $name, ?string $database = null): Collection { return $this->_client->selectCollection($database ?? $this->_database, $name); } }