From c9ebbbdf89e643d7510b9f1638d157c748a20db9 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Thu, 30 Apr 2015 15:34:33 -0400 Subject: [PATCH] PHPLIB-89: String getters for Database and Collection classes --- src/Collection.php | 25 +++++++++++++++++++++++-- src/Database.php | 20 ++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/Collection.php b/src/Collection.php index 0c3d1f036..a3cddee23 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -69,6 +69,16 @@ public function __construct(Manager $manager, $namespace, WriteConcern $writeCon list($this->dbname, $this->collname) = explode(".", $namespace, 2); } + /** + * Return the collection namespace. + * + * @param string + */ + public function __toString() + { + return $this->ns; + } + /** * Runs an aggregation framework pipeline * @@ -629,7 +639,7 @@ public function getBulkOptions() } /** - * Returns the CollectionName this object operates on + * Return the collection name. * * @return string */ @@ -677,7 +687,7 @@ public function getCountOptions() } /** - * Returns the DatabaseName this object operates on + * Return the database name. * * @return string */ @@ -931,6 +941,17 @@ public function getFindOptions() ); } + /** + * Return the collection namespace. + * + * @see http://docs.mongodb.org/manual/faq/developers/#faq-dev-namespace + * @return string + */ + public function getNamespace() + { + return $this->ns; + } + /** * Retrieves all Write options with their default values. * diff --git a/src/Database.php b/src/Database.php index b50a9ea48..8ca8d11c4 100644 --- a/src/Database.php +++ b/src/Database.php @@ -41,6 +41,16 @@ public function __construct(Manager $manager, $databaseName, WriteConcern $write $this->readPreference = $readPreference; } + /** + * Return the database name. + * + * @param string + */ + public function __toString() + { + return $this->databaseName; + } + /** * Create a new collection explicitly. * @@ -89,6 +99,16 @@ public function dropCollection($collectionName) return $this->manager->executeCommand($this->databaseName, $command, $readPreference); } + /** + * Returns the database name. + * + * @return string + */ + public function getDatabaseName() + { + return $this->databaseName; + } + /** * Returns information for all collections in this database. *