mirror of
https://github.com/predis/predis.git
synced 2026-08-30 04:02:22 +00:00
Implement ConnectionParameters::__toString().
This commit is contained in:
@@ -83,6 +83,7 @@ class ConnectionParameters {
|
||||
$query = explode('&', $parsed['query']);
|
||||
$parsed = array_reduce($query, 'self::paramsExtractor', $parsed);
|
||||
}
|
||||
unset($parsed['query']);
|
||||
return $this->filter($parsed);
|
||||
}
|
||||
|
||||
@@ -118,4 +119,25 @@ class ConnectionParameters {
|
||||
$value = $this->tryInitializeValue($parameter);
|
||||
return isset($value);
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
$str = null;
|
||||
if ($this->scheme === 'unix') {
|
||||
$str = "{$this->scheme}://{$this->path}";
|
||||
}
|
||||
else {
|
||||
$str = "{$this->scheme}://{$this->host}:{$this->port}";
|
||||
}
|
||||
|
||||
$query = array();
|
||||
$reject = array('scheme', 'host', 'port', 'password', 'path');
|
||||
foreach ($this->_parameters as $k => $v) {
|
||||
if (in_array($k, $reject) || $v === null) {
|
||||
continue;
|
||||
}
|
||||
$v = $v === false ? '0' : $v;
|
||||
$query[] = $k . '=' . ($v === false ? '0' : $v);
|
||||
}
|
||||
return count($query) > 0 ? ($str . '/?' . implode('&', $query)) : $str;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user