2
2
3
3
namespace MongoDB \Model ;
4
4
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
+ */
5
16
class CollectionInfo
6
17
{
7
- private $ name ;
8
- private $ options ;
18
+ private $ info ;
9
19
10
20
/**
11
21
* Constructor.
@@ -14,8 +24,7 @@ class CollectionInfo
14
24
*/
15
25
public function __construct (array $ info )
16
26
{
17
- $ this ->name = (string ) $ info ['name ' ];
18
- $ this ->options = isset ($ info ['options ' ]) ? (array ) $ info ['options ' ] : array ();
27
+ $ this ->info = $ info ;
19
28
}
20
29
21
30
/**
@@ -25,7 +34,7 @@ public function __construct(array $info)
25
34
*/
26
35
public function getName ()
27
36
{
28
- return $ this ->name ;
37
+ return ( string ) $ this ->info [ ' name ' ] ;
29
38
}
30
39
31
40
/**
@@ -35,7 +44,7 @@ public function getName()
35
44
*/
36
45
public function getOptions ()
37
46
{
38
- return $ this ->options ;
47
+ return isset ( $ this ->info [ ' options ' ]) ? ( array ) $ this -> info [ ' options ' ] : array () ;
39
48
}
40
49
41
50
/**
@@ -45,7 +54,7 @@ public function getOptions()
45
54
*/
46
55
public function isCapped ()
47
56
{
48
- return isset ($ this ->options [ ' capped ' ]) ? ( boolean ) $ this -> options ['capped ' ] : false ;
57
+ return ! empty ($ this ->info [ ' options ' ] ['capped ' ]) ;
49
58
}
50
59
51
60
/**
@@ -55,7 +64,7 @@ public function isCapped()
55
64
*/
56
65
public function getCappedMax ()
57
66
{
58
- return isset ($ this ->options ['max ' ]) ? (integer ) $ this ->options ['max ' ] : null ;
67
+ return isset ($ this ->info [ ' options ' ] ['max ' ]) ? (integer ) $ this ->info [ ' options ' ] ['max ' ] : null ;
59
68
}
60
69
61
70
/**
@@ -65,6 +74,6 @@ public function getCappedMax()
65
74
*/
66
75
public function getCappedSize ()
67
76
{
68
- return isset ($ this ->options ['size ' ]) ? (integer ) $ this ->options ['size ' ] : null ;
77
+ return isset ($ this ->info [ ' options ' ] ['size ' ]) ? (integer ) $ this ->info [ ' options ' ] ['size ' ] : null ;
69
78
}
70
79
}
0 commit comments