diff --git a/src/Client.php b/src/Client.php new file mode 100644 index 000000000..f0140895d --- /dev/null +++ b/src/Client.php @@ -0,0 +1,62 @@ +manager = new Manager($uri, $options, $driverOptions); + } + + /** + * Select a database + * + * It acts as a bridge to access specific database commands + * + * @param string $databaseName The database to select + * @param WriteConcern $writeConcern Default Write Concern to apply + * @param ReadPreference $readPreferences Default Read Preferences to apply + */ + public function selectDatabase($databaseName, WriteConcern $writeConcern = null, ReadPreference $readPreferences = null) + { + return new Database($this->manager, $databaseName, $writeConcern, $readPreferences); + } + + /** + * Select a specific collection in a database + * + * It acts as a bridge to access specific collection commands + * + * @param string $databaseName The database where the $collectionName exists + * @param string $collectionName The collection to select + * @param WriteConcern $writeConcern Default Write Concern to apply + * @param ReadPreference $readPreferences Default Read Preferences to apply + */ + public function selectCollection($databaseName, $collectionName, WriteConcern $writeConcern = null, ReadPreference $readPreferences = null) + { + return new Collection($this->manager, "{$databaseName}.{$collectionName}", $writeConcern, $readPreferences); + } + +} + diff --git a/src/Database.php b/src/Database.php new file mode 100644 index 000000000..d56de3bad --- /dev/null +++ b/src/Database.php @@ -0,0 +1,51 @@ +manager = $manager; + $this->dbname = $dbname; + $this->wc = $wc; + $this->rp = $rp; + } + + /** + * Select a specific collection in this database + * + * It acts as a bridge to access specific collection commands + * + * @param string $collectionName The collection to select + * @param WriteConcern $writeConcern Default Write Concern to apply + * @param ReadPreference $readPreferences Default Read Preferences to apply + */ + public function selectCollection($collectionName, WriteConcern $writeConcern = null, ReadPreference $readPreferences = null) + { + return new Collection($this->manager, "{$this->dbname}.{$collectionName}", $writeConcern, $readPreferences); + } + +} + +