Skip to content

Commit 3815890

Browse files
committed
Prevent cascading resolution of the bucket option
1 parent 9c7b6ba commit 3815890

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

src/MongoDBServiceProvider.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,14 @@ private function registerFlysystemAdapter(): void
9494

9595
$bucket = $config['bucket'] ?? null;
9696

97-
// Get the bucket from a factory function
9897
if ($bucket instanceof Closure) {
98+
// Get the bucket from a factory function
9999
$bucket = $bucket($app, $config);
100-
}
101-
102-
// Get the bucket from a service
103-
if (is_string($bucket) && $app->has($bucket)) {
100+
} elseif (is_string($bucket) && $app->has($bucket)) {
101+
// Get the bucket from a service
104102
$bucket = $app->get($bucket);
105-
}
106-
107-
// Get the bucket from the database connection
108-
if (is_string($bucket) || $bucket === null) {
103+
} elseif (is_string($bucket) || $bucket === null) {
104+
// Get the bucket from the database connection
109105
$connection = $app['db']->connection($config['connection']);
110106
if (! $connection instanceof Connection) {
111107
throw new InvalidArgumentException(sprintf('The database connection "%s" does not use the "mongodb" driver.', $config['connection'] ?? $app['config']['database.default']));
@@ -114,7 +110,9 @@ private function registerFlysystemAdapter(): void
114110
$bucket = $connection->getMongoClient()
115111
->selectDatabase($config['database'] ?? $connection->getDatabaseName())
116112
->selectGridFSBucket(['bucketName' => $config['bucket'] ?? 'fs', 'disableMD5' => true]);
117-
} elseif (! $bucket instanceof Bucket) {
113+
}
114+
115+
if (! $bucket instanceof Bucket) {
118116
throw new InvalidArgumentException(sprintf('Unexpected value for GridFS "bucket" configuration. Expecting "%s". Got "%s"', Bucket::class, get_debug_type($bucket)));
119117
}
120118

tests/FilesystemsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function testInvalidOptions(array $options, string $message)
110110
Storage::disk($this->dataName());
111111
}
112112

113-
public function testReadOnlyAndThrowOption()
113+
public function testReadOnlyAndThrowOptions()
114114
{
115115
$this->app['config']->set('filesystems.disks.gridfs-readonly', [
116116
'driver' => 'gridfs',

0 commit comments

Comments
 (0)