|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace MongoDB; |
| 4 | + |
| 5 | +use MongoDB\Driver\Manager; |
| 6 | +use MongoDB\Database; |
| 7 | +use MongoDB\Collection; |
| 8 | + |
| 9 | +class Client |
| 10 | +{ |
| 11 | + private $manager; |
| 12 | + private $wc; |
| 13 | + private $rp; |
| 14 | + |
| 15 | + |
| 16 | + /** |
| 17 | + * Constructs new Client instance |
| 18 | + * |
| 19 | + * This is the suggested main entry point using phongo. |
| 20 | + * It acts as a bridge to access individual databases and collection tools |
| 21 | + * which are provided in this namespace. |
| 22 | + * |
| 23 | + * @param Manager $uri The MongoDB URI to connect to |
| 24 | + * @param WriteConcern $options URI Options |
| 25 | + * @param ReadPreference $driverOptions Driver specific options |
| 26 | + */ |
| 27 | + public function __construct($uri, $options, $driverOptions) |
| 28 | + { |
| 29 | + $this->manager = new Manager($uri, $options, $driverOptions); |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * Select a database |
| 34 | + * |
| 35 | + * It acts as a bridge to access specific database commands |
| 36 | + * |
| 37 | + * @param string $databaseName The database to select |
| 38 | + * @param WriteConcern $writeConcern Default Write Concern to apply |
| 39 | + * @param ReadPreference $readPreferences Default Read Preferences to apply |
| 40 | + */ |
| 41 | + public function selectDatabase($databaseName, WriteConcern $writeConcern = null, ReadPreference $readPreferences = null) |
| 42 | + { |
| 43 | + return new Database($this->manager, $databaseName, $writeConcern, $readPreferences); |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * Select a specific collection in a database |
| 48 | + * |
| 49 | + * It acts as a bridge to access specific collection commands |
| 50 | + * |
| 51 | + * @param string $databaseName The database where the $collectionName exists |
| 52 | + * @param string $collectionName The collection to select |
| 53 | + * @param WriteConcern $writeConcern Default Write Concern to apply |
| 54 | + * @param ReadPreference $readPreferences Default Read Preferences to apply |
| 55 | + */ |
| 56 | + public function selectCollection($databaseName, $collectionName, WriteConcern $writeConcern = null, ReadPreference $readPreferences = null) |
| 57 | + { |
| 58 | + return new Collection($this->manager, "{$databaseName}.{$collectionName}", $writeConcern, $readPreferences); |
| 59 | + } |
| 60 | + |
| 61 | +} |
| 62 | + |
0 commit comments