8000 #37180 don't deprecate before throwing InvalidArgumentException · kralos/symfony@b6e06a6 · GitHub
[go: up one dir, main page]

Skip to content

Commit b6e06a6

Browse files
author
Joe Bennett
committed
symfony#37180 don't deprecate before throwing InvalidArgumentException
1 parent 845adfb commit b6e06a6

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/Symfony/Component/Lock/Store/MongoDbStore.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,22 +117,23 @@ public function __construct($mongo, array $options = [], float $initialTtl = 300
117117
if (isset($parsedUrl['query'])) {
118118
parse_str($parsedUrl['query'], $query);
119119
}
120-
if (isset($query['collection'])) {
121-
trigger_deprecation('symfony/lock', '5.2', 'Constructing a "%s" by passing the "collection" via a connection URI is deprecated. Either contruct with a "%s" or pass it via $options instead.', __CLASS__, Collection::class);
122-
}
123120
$this->options['collection'] = $this->options['collection'] ?? $query['collection'] ?? null;
124121
$authSource = $this->options['uriOptions']['authSource'] ?? $query['authSource'] ?? null;
125122
$pathDb = ltrim($parsedUrl['path'] ?? '', '/') ?: null;
126-
if (null === $this->options['database'] && null !== $pathDb) {
127-
trigger_deprecation('symfony/lock', '5.2', 'Constructing a "%s" by passing the "database" via a connection URI is deprecated. Either contruct with a "%s" or pass it via $options instead.', __CLASS__, Collection::class);
128-
}
123+
$databaseDerivedFromPath = null === $this->options['database'] && null !== $pathDb && $authSource !== $pathDb;
129124
$this->options['database'] = $this->options['database'] ?? $pathDb;
130125
if (null === $this->options['database']) {
131126
throw new InvalidArgumentException(sprintf('"%s()" requires the "database" to be passed via $options or the URI path.', __METHOD__));
132127
}
133128
if (null === $this->options['collection']) {
134129
throw new InvalidArgumentException(sprintf('"%s()" requires the "collection" to be passed via $options or the URI querystring.', __METHOD__));
135130
}
131+
if ($databaseDerivedFromPath) {
132+
trigger_deprecation('symfony/lock', '5.2', 'Constructing a "%s" by passing the "database" via a connection URI is deprecated. Either contruct with a "%s" or pass it via $options instead.', __CLASS__, Collection::class);
133+
}
134+
if (isset($query['collection'])) {
135+
trigger_deprecation('symfony/lock', '5.2', 'Constructing a "%s" by passing the "collection" via a connection URI is deprecated. Either contruct with a "%s" or pass it via $options instead.', __CLASS__, Collection::class);
136+
}
136137

137138
$this->uri = $mongo;
138139
} else {

src/Symfony/Component/Lock/Tests/Store/MongoDbStoreTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,12 @@ public function provideConstructorArgs()
119119
yield [$collection, []];
120120

121121
yield ['mongodb://localhost/', ['database' => 'test', 'collection' => 'lock']];
122-
yield ['mongodb://localhost/authDb', ['database' => 'test', 'collection' => 'lock']];
122+
yield ['mongodb://user:pass@localhost/authDb', ['database' => 'test', 'collection' => 'lock']];
123+
yield ['mongodb://user:pass@localhost/authDb?authSource=authDb', ['database' => 'test', 'collection' => 'lock']];
124+
yield ['mongodb://user:pass@localhost/?authSource=authDb', ['database' => 'test', 'collection' => 'lock']];
125+
yield ['mongodb://user:pass@localhost/authDb?authSource=authDb', ['database' => 'test', 'collection' => 'lock', 'uriOptions' => ['authSource' => 'authDb']]];
126+
yield ['mongodb://user:pass@localhost/?authSource=authDb', ['database' => 'test', 'collection' => 'lock', 'uriOptions' => ['authSource' => 'authDb']]];
127+
yield ['mongodb://user:pass@localhost/', ['database' => 'test', 'collection' => 'lock', 'uriOptions' => ['authSource' => 'authDb']]];
123128
}
124129

125130
/**
@@ -144,6 +149,10 @@ public function testDeprecatedDatabaseConstructionMethods($mongo, array $options
144149
public function provideDeprecatedDatabaseConstructorArgs()
145150
{
146151
yield ['mongodb://localhost/test', ['collection' => 'lock']];
152+
yield ['mongodb://user:pass@localhost/authDb', ['collection' => 'lock']];
153+
yield ['mongodb://user:pass@localhost/authDb?authSource=authDb', ['collection' => 'lock']];
154+
yield ['mongodb://user:pass@localhost/authDb?authSource=authDb', ['collection' => 'lock', 'uriOptions' => ['authSource' => 'authDb']]];
155+
yield ['mongodb://user:pass@localhost/authDb', ['collection' => 'lock', 'uriOptions' => ['authSource' => 'authDb']]];
147156
}
148157

149158
/**

0 commit comments

Comments
 (0)
0