Completed
Pull Request — master (#20)
by
unknown
02:53
created

MongoDB::getCollectionInfo()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 24
rs 8.6846
cc 4
eloc 14
nc 6
nop 1
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 */
15
16
use Alcaeus\MongoDbAdapter\Helper;
17
use Alcaeus\MongoDbAdapter\TypeConverter;
18
use Alcaeus\MongoDbAdapter\ExceptionConverter;
19
use MongoDB\Model\CollectionInfo;
20
21
/**
22
 * Instances of this class are used to interact with a database.
23
 * @link http://www.php.net/manual/en/class.mongodb.php
24
 */
25
class MongoDB
1 ignored issue
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
26
{
27
    use Helper\ReadPreference;
28
    use Helper\SlaveOkay;
29
    use Helper\WriteConcern;
30
31
    const PROFILING_OFF = 0;
32
    const PROFILING_SLOW = 1;
33
    const PROFILING_ON = 2;
34
35
    /**
36
     * @var MongoClient
37
     */
38
    protected $connection;
39
40
    /**
41
     * @var \MongoDB\Database
42
     */
43
    protected $db;
44
45
    /**
46
     * @var string
47
     */
48
    protected $name;
49
50
    /**
51
     * Creates a new database
52
     *
53
     * This method is not meant to be called directly. The preferred way to create an instance of MongoDB is through {@see Mongo::__get()} or {@see Mongo::selectDB()}.
54
     * @link http://www.php.net/manual/en/mongodb.construct.php
55
     * @param MongoClient $conn Database connection.
56
     * @param string $name Database name.
57
     * @throws Exception
58
     * @return MongoDB Returns the database.
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
59
     */
60
    public function __construct(MongoClient $conn, $name)
61
    {
62
        $this->connection = $conn;
63
        $this->name = $name;
64
65
        $this->setReadPreferenceFromArray($conn->getReadPreference());
66
        $this->setWriteConcernFromArray($conn->getWriteConcern());
67
68
        $this->createDatabaseObject();
69
    }
70
71
    /**
72
     * @return \MongoDB\Database
73
     * @internal This method is not part of the ext-mongo API
74
     */
75
    public function getDb()
76
    {
77
        return $this->db;
78
    }
79
80
    /**
81
     * The name of this database
82
     *
83
     * @link http://www.php.net/manual/en/mongodb.--tostring.php
84
     * @return string Returns this database's name.
85
     */
86
    public function __toString()
87
    {
88
        return $this->name;
89
    }
90
91
    /**
92
     * Gets a collection
93
     *
94
     * @link http://www.php.net/manual/en/mongodb.get.php
95
     * @param string $name The name of the collection.
96
     * @return MongoCollection
97
     */
98
    public function __get($name)
99
    {
100
        // Handle w and wtimeout properties that replicate data stored in $readPreference
101
        if ($name === 'w' || $name === 'wtimeout') {
102
            return $this->getWriteConcern()[$name];
103
        }
104
105
        return $this->selectCollection($name);
106
    }
107
108
    /**
109
     * @param string $name
110
     * @param mixed $value
111
     */
112 View Code Duplication
    public function __set($name, $value)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
113
    {
114
        if ($name === 'w' || $name === 'wtimeout') {
115
            $this->setWriteConcernFromArray([$name => $value] + $this->getWriteConcern());
116
            $this->createDatabaseObject();
117
        }
118
    }
119
120
    /**
121
     * Returns information about collections in this database
122
     *
123
     * @link http://www.php.net/manual/en/mongodb.getcollectioninfo.php
124
     * @param array $options An array of options for listing the collections.
125
     * @return array
126
     */
127
    public function getCollectionInfo(array $options = [])
128
    {
129
        // The includeSystemCollections option is no longer supported
130
        if (isset($options['includeSystemCollections'])) {
131
            unset($options['includeSystemCollections']);
132
        }
133
134
        try {
135
            $collections = $this->db->listCollections($options);
136
        } catch (\MongoDB\Driver\Exception\ExecutionTimeoutException $e) {
1 ignored issue
show
Bug introduced by
The class MongoDB\Driver\Exception\ExecutionTimeoutException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
137
            throw new \MongoExecutionTimeoutException($e->getMessage(), $e->getCode(), $e);
138
        } catch (\MongoDB\Driver\Exception\Exception $e) {
1 ignored issue
show
Bug introduced by
The class MongoDB\Driver\Exception\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
139
            ExceptionConverter::toLegacy($e);
140
        }
141
142
        $getCollectionInfo = function (CollectionInfo $collectionInfo) {
143
            return [
144
                'name' => $collectionInfo->getName(),
145
                'options' => $collectionInfo->getOptions(),
146
            ];
147
        };
148
149
        return array_map($getCollectionInfo, iterator_to_array($collections));
150
    }
151
152
    /**
153
     * Get all collections from this database
154
     *
155
     * @link http://www.php.net/manual/en/mongodb.getcollectionnames.php
156
     * @param array $options An array of options for listing the collections.
157
     * @return array Returns the names of the all the collections in the database as an array
158
     */
159
    public function getCollectionNames(array $options = [])
160
    {
161
        // The includeSystemCollections option is no longer supported
162
        if (isset($options['includeSystemCollections'])) {
163
            unset($options['includeSystemCollections']);
164
        }
165
166
        try {
167
            $collections = $this->db->listCollections($options);
168
        } catch (\MongoDB\Driver\Exception\ExecutionTimeoutException $e) {
1 ignored issue
show
Bug introduced by
The class MongoDB\Driver\Exception\ExecutionTimeoutException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
169
            throw new \MongoExecutionTimeoutException($e->getMessage(), $e->getCode(), $e);
170
        } catch (\MongoDB\Driver\Exception\Exception $e) {
1 ignored issue
show
Bug introduced by
The class MongoDB\Driver\Exception\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
171
            ExceptionConverter::toLegacy($e);
172
        }
173
174
        $getCollectionName = function (CollectionInfo $collectionInfo) {
175
            return $collectionInfo->getName();
176
        };
177
178
        return array_map($getCollectionName, iterator_to_array($collections));
179
    }
180
181
    /**
182
     * @return MongoClient
183
     * @internal This method is not part of the ext-mongo API
184
     */
185
    public function getConnection()
186
    {
187
        return $this->connection;
188
    }
189
190
    /**
191
     * Fetches toolkit for dealing with files stored in this database
192
     *
193
     * @link http://www.php.net/manual/en/mongodb.getgridfs.php
194
     * @param string $prefix The prefix for the files and chunks collections.
195
     * @return MongoGridFS Returns a new gridfs object for this database.
196
     */
197
    public function getGridFS($prefix = "fs")
198
    {
199
        return new \MongoGridFS($this, $prefix, $prefix);
200
    }
201
202
    /**
203
     * Gets this database's profiling level
204
     *
205
     * @link http://www.php.net/manual/en/mongodb.getprofilinglevel.php
206
     * @return int Returns the profiling level.
207
     */
208
    public function getProfilingLevel()
209
    {
210
        $result = $this->command(['profile' => -1]);
211
212
        return ($result['ok'] && isset($result['was'])) ? $result['was'] : 0;
213
    }
214
215
    /**
216
     * Sets this database's profiling level
217
     *
218
     * @link http://www.php.net/manual/en/mongodb.setprofilinglevel.php
219
     * @param int $level Profiling level.
220
     * @return int Returns the previous profiling level.
221
     */
222
    public function setProfilingLevel($level)
223
    {
224
        $result = $this->command(['profile' => $level]);
225
226
        return ($result['ok'] && isset($result['was'])) ? $result['was'] : 0;
227
    }
228
229
    /**
230
     * Drops this database
231
     *
232
     * @link http://www.php.net/manual/en/mongodb.drop.php
233
     * @return array Returns the database response.
234
     */
235
    public function drop()
236
    {
237
        return TypeConverter::toLegacy($this->db->drop());
238
    }
239
240
    /**
241
     * Repairs and compacts this database
242
     *
243
     * @link http://www.php.net/manual/en/mongodb.repair.php
244
     * @param bool $preserve_cloned_files [optional] <p>If cloned files should be kept if the repair fails.</p>
245
     * @param bool $backup_original_files [optional] <p>If original files should be backed up.</p>
246
     * @return array <p>Returns db response.</p>
247
     */
248
    public function repair($preserve_cloned_files = FALSE, $backup_original_files = FALSE)
0 ignored issues
show
Unused Code introduced by
The parameter $preserve_cloned_files is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $backup_original_files is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
249
    {
250
        $this->notImplemented();
251
    }
252
253
    /**
254
     * Gets a collection
255
     *
256
     * @link http://www.php.net/manual/en/mongodb.selectcollection.php
257
     * @param string $name <b>The collection name.</b>
258
     * @throws Exception if the collection name is invalid.
259
     * @return MongoCollection Returns a new collection object.
260
     */
261
    public function selectCollection($name)
262
    {
263
        return new MongoCollection($this, $name);
264
    }
265
266
    /**
267
     * Creates a collection
268
     *
269
     * @link http://www.php.net/manual/en/mongodb.createcollection.php
270
     * @param string $name The name of the collection.
271
     * @param array $options
272
     * @return MongoCollection Returns a collection object representing the new collection.
273
     */
274
    public function createCollection($name, $options)
275
    {
276
        try {
277
            $this->db->createCollection($name, $options);
278
        } catch (\MongoDB\Driver\Exception\Exception $e) {
1 ignored issue
show
Bug introduced by
The class MongoDB\Driver\Exception\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
279
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by MongoDB::createCollection of type MongoCollection.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
280
        }
281
282
        return $this->selectCollection($name);
283
    }
284
285
    /**
286
     * Drops a collection
287
     *
288
     * @link http://www.php.net/manual/en/mongodb.dropcollection.php
289
     * @param MongoCollection|string $coll MongoCollection or name of collection to drop.
290
     * @return array Returns the database response.
291
     *
292
     * @deprecated Use MongoCollection::drop() instead.
293
     */
294
    public function dropCollection($coll)
295
    {
296
        if ($coll instanceof MongoCollection) {
297
            $coll = $coll->getName();
298
        }
299
300
        return TypeConverter::toLegacy($this->db->dropCollection((string) $coll));
301
    }
302
303
    /**
304
     * Get a list of collections in this database
305
     *
306
     * @link http://www.php.net/manual/en/mongodb.listcollections.php
307
     * @param array $options
308
     * @return MongoCollection[] Returns a list of MongoCollections.
309
     */
310
    public function listCollections(array $options = [])
311
    {
312
        return array_map([$this, 'selectCollection'], $this->getCollectionNames($options));
313
    }
314
315
    /**
316
     * Creates a database reference
317
     *
318
     * @link http://www.php.net/manual/en/mongodb.createdbref.php
319
     * @param string $collection The collection to which the database reference will point.
320
     * @param mixed $document_or_id
321
     * @return array Returns a database reference array.
322
     */
323 View Code Duplication
    public function createDBRef($collection, $document_or_id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
324
    {
325
        if ($document_or_id instanceof \MongoId) {
326
            $id = $document_or_id;
327
        } elseif (is_object($document_or_id)) {
328
            if (! isset($document_or_id->_id)) {
329
                return null;
330
            }
331
332
            $id = $document_or_id->_id;
333
        } elseif (is_array($document_or_id)) {
334
            if (! isset($document_or_id['_id'])) {
335
                return null;
336
            }
337
338
            $id = $document_or_id['_id'];
339
        } else {
340
            $id = $document_or_id;
341
        }
342
343
        return MongoDBRef::create($collection, $id, $this->name);
344
    }
345
346
347
    /**
348
     * Fetches the document pointed to by a database reference
349
     *
350
     * @link http://www.php.net/manual/en/mongodb.getdbref.php
351
     * @param array $ref A database reference.
352
     * @return array Returns the document pointed to by the reference.
353
     */
354
    public function getDBRef(array $ref)
355
    {
356
        return MongoDBRef::get($this, $ref);
357
    }
358
359
    /**
360
     * Runs JavaScript code on the database server.
361
     *
362
     * @link http://www.php.net/manual/en/mongodb.execute.php
363
     * @param MongoCode|string $code Code to execute.
364
     * @param array $args [optional] Arguments to be passed to code.
365
     * @return array Returns the result of the evaluation.
366
     */
367
    public function execute($code, array $args = [])
368
    {
369
        return $this->command(['eval' => $code, 'args' => $args]);
370
    }
371
372
    /**
373
     * Execute a database command
374
     *
375
     * @link http://www.php.net/manual/en/mongodb.command.php
376
     * @param array $data The query to send.
377
     * @param array $options
378
     * @return array Returns database response.
379
     */
380
    public function command(array $data, $options = [], &$hash = null)
0 ignored issues
show
Unused Code introduced by
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $hash is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
381
    {
382
        try {
383
            $cursor = new \MongoCommandCursor($this->connection, $this->name, $data);
384
            $cursor->setReadPreference($this->getReadPreference());
0 ignored issues
show
Documentation introduced by
$this->getReadPreference() is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
385
386
            return iterator_to_array($cursor)[0];
387
        } catch (\MongoDB\Driver\Exception\ExecutionTimeoutException $e) {
1 ignored issue
show
Bug introduced by
The class MongoDB\Driver\Exception\ExecutionTimeoutException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
388
            throw new MongoCursorTimeoutException($e->getMessage(), $e->getCode(), $e);
389
        } catch (\MongoDB\Driver\Exception\RuntimeException $e) {
0 ignored issues
show
Bug introduced by
The class MongoDB\Driver\Exception\RuntimeException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
390
            return [
391
                'ok' => 0,
392
                'errmsg' => $e->getMessage(),
393
                'code' => $e->getCode(),
394
            ];
395
        } catch (\MongoDB\Driver\Exception\Excepiton $e) {
0 ignored issues
show
Bug introduced by
The class MongoDB\Driver\Exception\Excepiton does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
396
            ExceptionConverter::toLegacy($e);
397
        }
398
    }
399
400
    /**
401
     * Check if there was an error on the most recent db operation performed
402
     *
403
     * @link http://www.php.net/manual/en/mongodb.lasterror.php
404
     * @return array Returns the error, if there was one.
405
     */
406
    public function lastError()
407
    {
408
        return $this->command(array('getLastError' => 1));
409
    }
410
411
    /**
412
     * Checks for the last error thrown during a database operation
413
     *
414
     * @link http://www.php.net/manual/en/mongodb.preverror.php
415
     * @return array Returns the error and the number of operations ago it occurred.
416
     */
417
    public function prevError()
418
    {
419
        return $this->command(array('getPrevError' => 1));
420
    }
421
422
    /**
423
     * Clears any flagged errors on the database
424
     *
425
     * @link http://www.php.net/manual/en/mongodb.reseterror.php
426
     * @return array Returns the database response.
427
     */
428
    public function resetError()
429
    {
430
        return $this->command(array('resetError' => 1));
431
    }
432
433
    /**
434
     * Creates a database error
435
     *
436
     * @link http://www.php.net/manual/en/mongodb.forceerror.php
437
     * @return boolean Returns the database response.
438
     */
439
    public function forceError()
440
    {
441
        return $this->command(array('forceerror' => 1));
442
    }
443
444
    /**
445
     * Log in to this database
446
     *
447
     * @link http://www.php.net/manual/en/mongodb.authenticate.php
448
     * @param string $username The username.
449
     * @param string $password The password (in plaintext).
450
     * @return array Returns database response. If the login was successful, it will return 1.
451
     *
452
     * @deprecated This method is not implemented, supply authentication credentials through the connection string instead.
453
     */
454
    public function authenticate($username, $password)
0 ignored issues
show
Unused Code introduced by
The parameter $username is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $password is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
455
    {
456
        throw new \Exception('The MongoDB::authenticate method is not supported. Please supply authentication credentials through the connection string');
457
    }
458
459
    /**
460
     * {@inheritdoc}
461
     */
462
    public function setReadPreference($readPreference, $tags = null)
463
    {
464
        $result = $this->setReadPreferenceFromParameters($readPreference, $tags);
465
        $this->createDatabaseObject();
466
467
        return $result;
468
    }
469
470
    /**
471
     * {@inheritdoc}
472
     */
473
    public function setWriteConcern($wstring, $wtimeout = 0)
474
    {
475
        $result = $this->setWriteConcernFromParameters($wstring, $wtimeout);
476
        $this->createDatabaseObject();
477
478
        return $result;
479
    }
480
481
    protected function notImplemented()
482
    {
483
        throw new \Exception('Not implemented');
484
    }
485
486
    /**
487
     * @return \MongoDB\Database
488
     */
489 View Code Duplication
    private function createDatabaseObject()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
490
    {
491
        $options = [
492
            'readPreference' => $this->readPreference,
493
            'writeConcern' => $this->writeConcern,
494
        ];
495
496
        if ($this->db === null) {
497
            $this->db = $this->connection->getClient()->selectDatabase($this->name, $options);
498
        } else {
499
            $this->db = $this->db->withOptions($options);
500
        }
501
    }
502
}
503