Skip to content

Commit eb4956c

Browse files
committed
Fixed #692
1 parent 3c86342 commit eb4956c

2 files changed

Lines changed: 33 additions & 9 deletions

File tree

lib/Phpfastcache/Drivers/Mongodb/Config.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ class Config extends ConfigurationOption
7070
*/
7171
protected $driverOptions = [];
7272

73+
/**
74+
* @var string
75+
*/
76+
protected $protocol = 'mongodb';
77+
7378
/**
7479
* @return string
7580
*/
@@ -250,4 +255,22 @@ public function setDriverOptions(array $driverOptions): self
250255
$this->driverOptions = $driverOptions;
251256
return $this;
252257
}
258+
259+
/**
260+
* @return string
261+
*/
262+
public function getProtocol(): string
263+
{
264+
return $this->protocol;
265+
}
266+
267+
/**
268+
* @param string $protocol
269+
* @return self
270+
*/
271+
public function setProtocol(string $protocol): self
272+
{
273+
$this->protocol = $protocol;
274+
return $this;
275+
}
253276
}

lib/Phpfastcache/Drivers/Mongodb/Driver.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,28 +228,29 @@ protected function buildConnectionURI($databaseName = ''): string
228228
$servers = $this->getConfig()->getServers();
229229
$options = $this->getConfig()->getOptions();
230230

231+
$protocol = $this->getConfig()->getProtocol();
231232
$host = $this->getConfig()->getHost();
232233
$port = $this->getConfig()->getPort();
233234
$username = $this->getConfig()->getUsername();
234235
$password = $this->getConfig()->getPassword();
235236

236237
if( \count($servers) > 0 ){
237-
$host = \array_reduce($servers, function($carry, $data){
238+
$host = \array_reduce($servers, static function($carry, $data){
238239
$carry .= ($carry === '' ? '' : ',').$data['host'].':'.$data['port'];
239240
return $carry;
240241
}, '');
241242
$port = false;
242243
}
243244

244-
return implode('', [
245-
'mongodb://',
246-
($username ?: ''),
247-
($password ? ":{$password}" : ''),
248-
($username ? '@' : ''),
245+
return \implode('', [
246+
"{$protocol}://",
247+
$username ?: '',
248+
$password ? ":{$password}" : '',
249+
$username ? '@' : '',
249250
$host,
250-
($port !== 27017 && $port !== false ? ":{$port}" : ''),
251-
($databaseName ? "/{$databaseName}" : ''),
252-
(\count($options) > 0 ? '?'.\http_build_query($options) : ''),
251+
$port !== 27017 && $port !== false ? ":{$port}" : '',
252+
$databaseName ? "/{$databaseName}" : '',
253+
\count($options) > 0 ? '?'.\http_build_query($options) : '',
253254
]);
254255
}
255256

0 commit comments

Comments
 (0)