Skip to content

Commit 85e4b9d

Browse files
committed
develop
1 parent d5459f5 commit 85e4b9d

File tree

1 file changed

+14
-28
lines changed

1 file changed

+14
-28
lines changed

pkg/mongodb/MongodbConnectionFactory.php

+14-28
Original file line numberDiff line numberDiff line change
@@ -55,58 +55,44 @@ public function createContext()
5555
public static function parseDsn($dsn)
5656
{
5757
$parsedUrl = parse_url($dsn);
58-
5958
if (false === $parsedUrl) {
6059
throw new \LogicException(sprintf('Failed to parse DSN "%s"', $dsn));
6160
}
62-
6361
if (empty($parsedUrl['scheme'])) {
6462
throw new \LogicException('Schema is empty');
6563
}
66-
6764
$supported = [
6865
'mongodb' => true,
6966
];
70-
7167
if (false == isset($parsedUrl['scheme'])) {
7268
throw new \LogicException(sprintf(
7369
'The given DSN schema "%s" is not supported. There are supported schemes: "%s".',
7470
$parsedUrl['scheme'],
7571
implode('", "', array_keys($supported))
7672
));
7773
}
78-
79-
if ($parsedUrl['scheme'].':' === $dsn) {
74+
if ('mongodb:' === $dsn) {
8075
return [
81-
'uri' => $parsedUrl['scheme'].'://127.0.0.1/',
76+
'uri' => 'mongodb://127.0.0.1/',
8277
];
8378
}
84-
85-
$config['uri'] = $parsedUrl['scheme'].'://'.$parsedUrl['host'];
86-
79+
$config['uri'] = $dsn;
8780
if (isset($parsedUrl['path']) && '/' !== $parsedUrl['path']) {
88-
$pathArr = explode('/', $parsedUrl['path']);
89-
81+
$pathParts = explode('/', $parsedUrl['path']);
9082
//DB name
91-
if ($pathArr[1]) {
92-
$config['dbname'] = $pathArr[1];
93-
$config['uri'] .= '/'.$pathArr[1];
94-
}
95-
96-
//Collection name
97-
if ($pathArr[2]) {
98-
$config['collection_name'] = $pathArr[2];
83+
if ($pathParts[1]) {
84+
$config['dbname'] = $pathParts[1];
9985
}
10086
}
101-
10287
if (isset($parsedUrl['query'])) {
103-
$config['uri'] .= '?'.$parsedUrl['query'];
104-
//get polling_interval value
105-
if (false !== strpos($parsedUrl['query'], 'polling_interval')) {
106-
preg_match_all('/polling_interval=([0-9]+)/', $parsedUrl['query'], $matches);
107-
if (isset($matches[1][0])) {
108-
$config['polling_interval'] = $matches[1][0];
109-
}
88+
$queryParts = null;
89+
parse_str($parsedUrl['query'], $queryParts);
90+
//get enqueue attributes values
91+
if (!empty($queryParts['polling_interval'])) {
92+
$config['polling_interval'] = $queryParts['polling_interval'];
93+
}
94+
if (!empty($queryParts['enqueue_collection'])) {
95+
$config['collection_name'] = $queryParts['enqueue_collection'];
11096
}
11197
}
11298

0 commit comments

Comments
 (0)