@@ -72,21 +72,21 @@ class Collection
72
72
* to use for collection operations. Defaults to the Manager's write
73
73
* concern.
74
74
*
75
- * @param Manager $manager Manager instance from the driver
76
- * @param string $namespace Collection namespace (e.g. "db.collection")
77
- * @param array $options Collection options
75
+ * @param Manager $manager Manager instance from the driver
76
+ * @param string $databaseName Database name
77
+ * @param string $collectionName Collection name
78
+ * @param array $options Collection options
78
79
* @throws InvalidArgumentException
79
80
*/
80
- public function __construct (Manager $ manager , $ namespace , array $ options = [])
81
+ public function __construct (Manager $ manager , $ databaseName , $ collectionName , array $ options = [])
81
82
{
82
- $ parts = explode ('. ' , $ namespace , 2 );
83
-
84
- if (count ($ parts ) != 2 || strlen ($ parts [0 ]) == 0 || strlen ($ parts [1 ]) == 0 ) {
85
- throw new InvalidArgumentException ('$namespace is invalid: ' . $ namespace );
83
+ if (strlen ($ databaseName ) < 1 ) {
84
+ throw new InvalidArgumentException ('$databaseName is invalid: ' . $ databaseName );
86
85
}
87
86
88
- $ this ->databaseName = $ parts [0 ];
89
- $ this ->collectionName = $ parts [1 ];
87
+ if (strlen ($ collectionName ) < 1 ) {
88
+ throw new InvalidArgumentException ('$collectionName is invalid: ' . $ collectionName );
89
+ }
90
90
91
91
if (isset ($ options ['readConcern ' ]) && ! $ options ['readConcern ' ] instanceof ReadConcern) {
92
92
throw InvalidArgumentException::invalidType ('"readConcern" option ' , $ options ['readConcern ' ], 'MongoDB\Driver\ReadConcern ' );
@@ -105,6 +105,8 @@ public function __construct(Manager $manager, $namespace, array $options = [])
105
105
}
106
106
107
107
$ this ->manager = $ manager ;
108
+ $ this ->databaseName = (string ) $ databaseName ;
109
+ $ this ->collectionName = (string ) $ collectionName ;
108
110
$ this ->readConcern = isset ($ options ['readConcern ' ]) ? $ options ['readConcern ' ] : $ this ->manager ->getReadConcern ();
109
111
$ this ->readPreference = isset ($ options ['readPreference ' ]) ? $ options ['readPreference ' ] : $ this ->manager ->getReadPreference ();
110
112
$ this ->typeMap = isset ($ options ['typeMap ' ]) ? $ options ['typeMap ' ] : self ::$ defaultTypeMap ;
@@ -133,6 +135,7 @@ public function __debugInfo()
133
135
/**
134
136
* Return the collection namespace (e.g. "db.collection").
135
137
*
138
+ * @see https://docs.mongodb.org/manual/faq/developers/#faq-dev-namespace
136
139
* @param string
137
140
*/
138
141
public function __toString ()
@@ -723,6 +726,6 @@ public function withOptions(array $options = [])
723
726
'writeConcern ' => $ this ->writeConcern ,
724
727
];
725
728
726
- return new Collection ($ this ->manager , $ this ->databaseName . ' . ' . $ this ->collectionName , $ options );
729
+ return new Collection ($ this ->manager , $ this ->databaseName , $ this ->collectionName , $ options );
727
730
}
728
731
}
0 commit comments