Skip to content

Commit f0ee8fb

Browse files
committed
PHPLIB-75: Refactor model classes and add class-level docs
1 parent 225ae3c commit f0ee8fb

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

src/Model/CollectionInfo.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,20 @@
22

33
namespace MongoDB\Model;
44

5+
/**
6+
* Collection information model class.
7+
*
8+
* This class models the collection information returned by the listCollections
9+
* command or, for legacy servers, queries on the "system.namespaces"
10+
* collection. It provides methods to access options for the collection.
11+
*
12+
* @api
13+
* @see MongoDB\Database::listCollections()
14+
* @see https://github.com/mongodb/specifications/blob/master/source/enumerate-collections.rst
15+
*/
516
class CollectionInfo
617
{
7-
private $name;
8-
private $options;
18+
private $info;
919

1020
/**
1121
* Constructor.
@@ -14,8 +24,7 @@ class CollectionInfo
1424
*/
1525
public function __construct(array $info)
1626
{
17-
$this->name = (string) $info['name'];
18-
$this->options = isset($info['options']) ? (array) $info['options'] : array();
27+
$this->info = $info;
1928
}
2029

2130
/**
@@ -25,7 +34,7 @@ public function __construct(array $info)
2534
*/
2635
public function getName()
2736
{
28-
return $this->name;
37+
return (string) $this->info['name'];
2938
}
3039

3140
/**
@@ -35,7 +44,7 @@ public function getName()
3544
*/
3645
public function getOptions()
3746
{
38-
return $this->options;
47+
return isset($this->info['options']) ? (array) $this->info['options'] : array();
3948
}
4049

4150
/**
@@ -45,7 +54,7 @@ public function getOptions()
4554
*/
4655
public function isCapped()
4756
{
48-
return isset($this->options['capped']) ? (boolean) $this->options['capped'] : false;
57+
return ! empty($this->info['options']['capped']);
4958
}
5059

5160
/**
@@ -55,7 +64,7 @@ public function isCapped()
5564
*/
5665
public function getCappedMax()
5766
{
58-
return isset($this->options['max']) ? (integer) $this->options['max'] : null;
67+
return isset($this->info['options']['max']) ? (integer) $this->info['options']['max'] : null;
5968
}
6069

6170
/**
@@ -65,6 +74,6 @@ public function getCappedMax()
6574
*/
6675
public function getCappedSize()
6776
{
68-
return isset($this->options['size']) ? (integer) $this->options['size'] : null;
77+
return isset($this->info['options']['size']) ? (integer) $this->info['options']['size'] : null;
6978
}
7079
}

src/Model/DatabaseInfo.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,19 @@
22

33
namespace MongoDB\Model;
44

5+
/**
6+
* Database information model class.
7+
*
8+
* This class models the database information returned by the listDatabases
9+
* command. It provides methods to access common database properties.
10+
*
11+
* @api
12+
* @see MongoDB\Client::listDatabases()
13+
* @see http://docs.mongodb.org/manual/reference/command/listDatabases/
14+
*/
515
class DatabaseInfo
616
{
7-
private $empty;
8-
private $name;
9-
private $sizeOnDisk;
17+
private $info;
1018

1119
/**
1220
* Constructor.
@@ -15,9 +23,7 @@ class DatabaseInfo
1523
*/
1624
public function __construct(array $info)
1725
{
18-
$this->name = (string) $info['name'];
19-
$this->empty = (boolean) $info['empty'];
20-
$this->sizeOnDisk = (integer) $info['sizeOnDisk'];
26+
$this->info = $info;
2127
}
2228

2329
/**
@@ -27,7 +33,7 @@ public function __construct(array $info)
2733
*/
2834
public function getName()
2935
{
30-
return $this->name;
36+
return (string) $this->info['name'];
3137
}
3238

3339
/**
@@ -37,7 +43,7 @@ public function getName()
3743
*/
3844
public function getSizeOnDisk()
3945
{
40-
return $this->sizeOnDisk;
46+
return (integer) $this->info['sizeOnDisk'];
4147
}
4248

4349
/**
@@ -47,6 +53,6 @@ public function getSizeOnDisk()
4753
*/
4854
public function isEmpty()
4955
{
50-
return $this->empty;
56+
return (boolean) $this->info['empty'];
5157
}
5258
}

0 commit comments

Comments
 (0)