Commit c3b622ab authored by Steve Porter's avatar Steve Porter

fix: fixes dsn connection strings by url encoding

parent f12f766d
...@@ -150,18 +150,37 @@ class Connection extends BaseConnection ...@@ -150,18 +150,37 @@ class Connection extends BaseConnection
} }
/** /**
* Create a DSN string from a configuration. * Determine if the given configuration array has a UNIX socket value.
* *
* @param array $config * @param array $config
* @return bool
*/
protected function hasDsnString(array $config)
{
return isset($config['dsn']) && ! empty($config['dsn']);
}
/**
* Get the DSN string for a socket configuration.
*
* @param array $config
* @return string * @return string
*/ */
protected function getDsn(array $config) protected function getDsnString(array $config)
{ {
// Check if the user passed a complete dsn to the configuration. $dsn = rawurlencode($config['dsn']);
if (!empty($config['dsn'])) {
return $config['dsn']; return "mongodb://{$dsn}";
} }
/**
* Get the DSN string for a host / port configuration.
*
* @param array $config
* @return string
*/
protected function getHostDsn(array $config)
{
// Treat host option as array of hosts // Treat host option as array of hosts
$hosts = is_array($config['host']) ? $config['host'] : [$config['host']]; $hosts = is_array($config['host']) ? $config['host'] : [$config['host']];
...@@ -178,6 +197,19 @@ class Connection extends BaseConnection ...@@ -178,6 +197,19 @@ class Connection extends BaseConnection
return 'mongodb://' . implode(',', $hosts) . ($auth_database ? '/' . $auth_database : ''); return 'mongodb://' . implode(',', $hosts) . ($auth_database ? '/' . $auth_database : '');
} }
/**
* Create a DSN string from a configuration.
*
* @param array $config
* @return string
*/
protected function getDsn(array $config)
{
return $this->hasDsnString($config)
? $this->getDsnString($config)
: $this->getHostDsn($config);
}
/** /**
* @inheritdoc * @inheritdoc
*/ */
......
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