You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
thrownewInvalidArgumentException(sprintf('"%s()" requires "%s" or "%s" or URI as first argument, "%s" given.', __METHOD__, Collection::class, Client::class, get_debug_type($mongo)));
112
+
}
113
+
114
+
if (!($mongoinstanceof Collection)) {
125
115
if (null === $this->options['database']) {
126
116
thrownewInvalidArgumentException(sprintf('"%s()" requires the "database" in the URI path or option when constructing with a URI.', __METHOD__));
127
117
}
128
118
if (null === $this->options['collection']) {
129
119
thrownewInvalidArgumentException(sprintf('"%s()" requires the "collection" in the URI querystring or option when constructing with a URI.', __METHOD__));
130
120
}
131
-
132
-
$this->uri = $mongo;
133
-
} else {
134
-
thrownewInvalidArgumentException(sprintf('"%s()" requires "%s" or "%s" or URI as first argument, "%s" given.', __METHOD__, Collection::class, Client::class, get_debug_type($mongo)));
135
121
}
136
122
137
123
if ($this->options['gcProbablity'] < 0.0 || $this->options['gcProbablity'] > 1.0) {
@@ -143,6 +129,42 @@ public function __construct($mongo, array $options = [], float $initialTtl = 300
143
129
}
144
130
}
145
131
132
+
/**
133
+
* Extract default database and collection from given connection uri and remove collection querystring
134
+
*
135
+
*/
136
+
privatefunctionskimUri(string$uri): string
137
+
{
138
+
if (false === $parsedUrl = parse_url($uri)) {
139
+
thrownewInvalidArgumentException(sprintf('The given MongoDB Connection URI "%s" is invalid.', $mongo));
140
+
}
141
+
142
+
$query = [];
143
+
if (isset($parsedUrl['query'])) {
144
+
parse_str($parsedUrl['query'], $query);
145
+
}
146
+
147
+
if (null === ($this->options['collection'] ?? null) && isset($query['collection'])) {
0 commit comments