Commit e41f69ad authored by Giacomo Fabbian's avatar Giacomo Fabbian

Merge branch 'master' into pr_1145

parents af8c2755 89fe91f7
......@@ -23,15 +23,15 @@
"illuminate/container": "^5.8|^6.0",
"illuminate/database": "^5.8|^6.0",
"illuminate/events": "^5.8|^6.0",
"mongodb/mongodb": "^1.4",
"cedx/coveralls": "^11.2"
"mongodb/mongodb": "^1.4"
},
"require-dev": {
"phpunit/phpunit": "^6.0|^7.0|^8.0",
"orchestra/testbench": "^3.1|^4.0",
"mockery/mockery": "^1.0",
"doctrine/dbal": "^2.5",
"phpunit/phpcov": "^6.0"
"phpunit/phpcov": "^6.0",
"cedx/coveralls": "^11.2"
},
"autoload": {
"psr-0": {
......
......@@ -38,7 +38,7 @@ class Connection extends BaseConnection
$this->connection = $this->createConnection($dsn, $config, $options);
// Select database
$this->db = $this->connection->selectDatabase($config['database']);
$this->db = $this->connection->selectDatabase($this->getDatabaseDsn($dsn, $config['database']));
$this->useDefaultPostProcessor();
......@@ -188,10 +188,21 @@ class Connection extends BaseConnection
// Check if we want to authenticate against a specific database.
$auth_database = isset($config['options']) && !empty($config['options']['database']) ? $config['options']['database'] : null;
return 'mongodb://' . implode(',', $hosts) . ($auth_database ? '/' . $auth_database : '');
}
/**
* Get database name from DSN string, if there is no database in DSN path - returns back $database argument.
* @param string $dsn
* @param $database
* @return string
*/
protected function getDatabaseDsn($dsn, $database)
{
$dsnDatabase = trim(parse_url($dsn, PHP_URL_PATH), '/');
return trim($dsnDatabase) ? $dsnDatabase : $database;
}
/**
* Create a DSN string from a configuration.
* @param array $config
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment