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
bug #37218 [Lock] MongoDbStore skim non-standard options from uri (kralos)
This PR was squashed before being merged into the 5.1 branch.
Discussion
----------
[Lock] MongoDbStore skim non-standard options from uri
| Q | A
| ------------- | ---
| Branch? | 5.1
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | Fix#37180
| License | MIT
| Doc PR |
Don't allow non-standard connection uri options reach `MongoDB\Client`
Commits
-------
67912fa [Lock] MongoDbStore skim non-standard options from uri
Copy file name to clipboardExpand all lines: src/Symfony/Component/Lock/Store/MongoDbStore.php
+49-24Lines changed: 49 additions & 24 deletions
Original file line number
Diff line number
Diff line change
@@ -72,8 +72,8 @@ class MongoDbStore implements BlockingStoreInterface
72
72
* driverOptions: Array of driver options. [used when $mongo is a URI]
73
73
*
74
74
* When using a URI string:
75
-
* the database is determined from the "database" option, otherwise the uri's path is used.
76
-
* the collection is determined from the "collection" option, otherwise the uri's "collection" querystring parameter is used.
75
+
* The database is determined from the uri's path, otherwise the "database" option is used. To specify an alternate authentication database; "authSource" uriOption or querystring parameter must be used.
76
+
* The collection is determined from the uri's "collection" querystring parameter, otherwise the "collection" option is used.
77
77
*
78
78
* For example: mongodb://myuser:mypass@myhost/mydatabase?collection=mycollection
79
79
*
@@ -104,34 +104,20 @@ public function __construct($mongo, array $options = [], float $initialTtl = 300
104
104
if ($mongoinstanceof Collection) {
105
105
$this->collection = $mongo;
106
106
} elseif ($mongoinstanceof Client) {
107
-
if (null === $this->options['database']) {
108
-
thrownewInvalidArgumentException(sprintf('"%s()" requires the "database" option when constructing with a "%s".', __METHOD__, Client::class));
109
-
}
110
-
if (null === $this->options['collection']) {
111
-
thrownewInvalidArgumentException(sprintf('"%s()" requires the "collection" option when constructing with a "%s".', __METHOD__, Client::class));
112
-
}
113
-
114
107
$this->client = $mongo;
115
108
} elseif (\is_string($mongo)) {
116
-
if (false === $parsedUrl = parse_url($mongo)) {
117
-
thrownewInvalidArgumentException(sprintf('The given MongoDB Connection URI "%s" is invalid.', $mongo));
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
-
thrownewInvalidArgumentException(sprintf('"%s()" requires the "database" in the URI path or option when constructing with a URI.', __METHOD__));
116
+
thrownewInvalidArgumentException(sprintf('"%s()" requires the "database" in the URI path or option.', __METHOD__));
127
117
}
128
118
if (null === $this->options['collection']) {
129
-
thrownewInvalidArgumentException(sprintf('"%s()" requires the "collection" in the URI querystring or option when constructing with a URI.', __METHOD__));
119
+
thrownewInvalidArgumentException(sprintf('"%s()" requires the "collection" in the URI querystring or option.', __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,45 @@ 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
+
* Non-standard parameters are removed from the URI to improve libmongoc's re-use of connections.
0 commit comments