Skip to content

Commit daed771

Browse files
committed
Merge pull request #10 from jmikola/phplib-89
PHPLIB-89: String getters for Database and Collection classes
2 parents 76d62e2 + c9ebbbd commit daed771

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

src/Collection.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ public function __construct(Manager $manager, $namespace, WriteConcern $writeCon
6969
list($this->dbname, $this->collname) = explode(".", $namespace, 2);
7070
}
7171

72+
/**
73+
* Return the collection namespace.
74+
*
75+
* @param string
76+
*/
77+
public function __toString()
78+
{
79+
return $this->ns;
80+
}
81+
7282
/**
7383
* Runs an aggregation framework pipeline
7484
*
@@ -629,7 +639,7 @@ public function getBulkOptions()
629639
}
630640

631641
/**
632-
* Returns the CollectionName this object operates on
642+
* Return the collection name.
633643
*
634644
* @return string
635645
*/
@@ -677,7 +687,7 @@ public function getCountOptions()
677687
}
678688

679689
/**
680-
* Returns the DatabaseName this object operates on
690+
* Return the database name.
681691
*
682692
* @return string
683693
*/
@@ -931,6 +941,17 @@ public function getFindOptions()
931941
);
932942
}
933943

944+
/**
945+
* Return the collection namespace.
946+
*
947+
* @see http://docs.mongodb.org/manual/faq/developers/#faq-dev-namespace
948+
* @return string
949+
*/
950+
public function getNamespace()
951+
{
952+
return $this->ns;
953+
}
954+
934955
/**
935956
* Retrieves all Write options with their default values.
936957
*

src/Database.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ public function __construct(Manager $manager, $databaseName, WriteConcern $write
4141
$this->readPreference = $readPreference;
4242
}
4343

44+
/**
45+
* Return the database name.
46+
*
47+
* @param string
48+
*/
49+
public function __toString()
50+
{
51+
return $this->databaseName;
52+
}
53+
4454
/**
4555
* Create a new collection explicitly.
4656
*
@@ -89,6 +99,16 @@ public function dropCollection($collectionName)
8999
return $this->manager->executeCommand($this->databaseName, $command, $readPreference);
90100
}
91101

102+
/**
103+
* Returns the database name.
104+
*
105+
* @return string
106+
*/
107+
public function getDatabaseName()
108+
{
109+
return $this->databaseName;
110+
}
111+
92112
/**
93113
* Returns information for all collections in this database.
94114
*

0 commit comments

Comments
 (0)