Commit 48b3de1c authored by Jeremy Mikola's avatar Jeremy Mikola

PHPLIB-75: Refactor model classes and add class-level docs

parent 2f63218a
...@@ -2,10 +2,20 @@ ...@@ -2,10 +2,20 @@
namespace MongoDB\Model; namespace MongoDB\Model;
/**
* Collection information model class.
*
* This class models the collection information returned by the listCollections
* command or, for legacy servers, queries on the "system.namespaces"
* collection. It provides methods to access options for the collection.
*
* @api
* @see MongoDB\Database::listCollections()
* @see https://github.com/mongodb/specifications/blob/master/source/enumerate-collections.rst
*/
class CollectionInfo class CollectionInfo
{ {
private $name; private $info;
private $options;
/** /**
* Constructor. * Constructor.
...@@ -14,8 +24,7 @@ class CollectionInfo ...@@ -14,8 +24,7 @@ class CollectionInfo
*/ */
public function __construct(array $info) public function __construct(array $info)
{ {
$this->name = (string) $info['name']; $this->info = $info;
$this->options = isset($info['options']) ? (array) $info['options'] : array();
} }
/** /**
...@@ -25,7 +34,7 @@ class CollectionInfo ...@@ -25,7 +34,7 @@ class CollectionInfo
*/ */
public function getName() public function getName()
{ {
return $this->name; return (string) $this->info['name'];
} }
/** /**
...@@ -35,7 +44,7 @@ class CollectionInfo ...@@ -35,7 +44,7 @@ class CollectionInfo
*/ */
public function getOptions() public function getOptions()
{ {
return $this->options; return isset($this->info['options']) ? (array) $this->info['options'] : array();
} }
/** /**
...@@ -45,7 +54,7 @@ class CollectionInfo ...@@ -45,7 +54,7 @@ class CollectionInfo
*/ */
public function isCapped() public function isCapped()
{ {
return isset($this->options['capped']) ? (boolean) $this->options['capped'] : false; return ! empty($this->info['options']['capped']);
} }
/** /**
...@@ -55,7 +64,7 @@ class CollectionInfo ...@@ -55,7 +64,7 @@ class CollectionInfo
*/ */
public function getCappedMax() public function getCappedMax()
{ {
return isset($this->options['max']) ? (integer) $this->options['max'] : null; return isset($this->info['options']['max']) ? (integer) $this->info['options']['max'] : null;
} }
/** /**
...@@ -65,6 +74,6 @@ class CollectionInfo ...@@ -65,6 +74,6 @@ class CollectionInfo
*/ */
public function getCappedSize() public function getCappedSize()
{ {
return isset($this->options['size']) ? (integer) $this->options['size'] : null; return isset($this->info['options']['size']) ? (integer) $this->info['options']['size'] : null;
} }
} }
...@@ -2,11 +2,19 @@ ...@@ -2,11 +2,19 @@
namespace MongoDB\Model; namespace MongoDB\Model;
/**
* Database information model class.
*
* This class models the database information returned by the listDatabases
* command. It provides methods to access common database properties.
*
* @api
* @see MongoDB\Client::listDatabases()
* @see http://docs.mongodb.org/manual/reference/command/listDatabases/
*/
class DatabaseInfo class DatabaseInfo
{ {
private $empty; private $info;
private $name;
private $sizeOnDisk;
/** /**
* Constructor. * Constructor.
...@@ -15,9 +23,7 @@ class DatabaseInfo ...@@ -15,9 +23,7 @@ class DatabaseInfo
*/ */
public function __construct(array $info) public function __construct(array $info)
{ {
$this->name = (string) $info['name']; $this->info = $info;
$this->empty = (boolean) $info['empty'];
$this->sizeOnDisk = (integer) $info['sizeOnDisk'];
} }
/** /**
...@@ -27,7 +33,7 @@ class DatabaseInfo ...@@ -27,7 +33,7 @@ class DatabaseInfo
*/ */
public function getName() public function getName()
{ {
return $this->name; return (string) $this->info['name'];
} }
/** /**
...@@ -37,7 +43,7 @@ class DatabaseInfo ...@@ -37,7 +43,7 @@ class DatabaseInfo
*/ */
public function getSizeOnDisk() public function getSizeOnDisk()
{ {
return $this->sizeOnDisk; return (integer) $this->info['sizeOnDisk'];
} }
/** /**
...@@ -47,6 +53,6 @@ class DatabaseInfo ...@@ -47,6 +53,6 @@ class DatabaseInfo
*/ */
public function isEmpty() public function isEmpty()
{ {
return $this->empty; return (boolean) $this->info['empty'];
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment