3636
3737class Collection
3838{
39- /* {{{ consts & vars */
40- protected $ manager ;
41- protected $ ns ;
42- protected $ wc ;
43- protected $ rp ;
44-
45- protected $ dbname ;
46- protected $ collname ;
47- /* }}} */
48-
39+ private $ collectionName ;
40+ private $ databaseName ;
41+ private $ manager ;
42+ private $ readPreference ;
43+ private $ writeConcern ;
4944
5045 /**
5146 * Constructs new Collection instance.
@@ -61,11 +56,10 @@ class Collection
6156 public function __construct (Manager $ manager , $ namespace , WriteConcern $ writeConcern = null , ReadPreference $ readPreference = null )
6257 {
6358 $ this ->manager = $ manager ;
64- $ this ->ns = (string ) $ namespace ;
65- $ this ->wc = $ writeConcern ;
66- $ this ->rp = $ readPreference ;
59+ $ this ->writeConcern = $ writeConcern ;
60+ $ this ->readPreference = $ readPreference ;
6761
68- list ($ this ->dbname , $ this ->collname ) = explode (". " , $ namespace , 2 );
62+ list ($ this ->databaseName , $ this ->collectionName ) = explode (". " , $ namespace , 2 );
6963 }
7064
7165 /**
@@ -75,7 +69,7 @@ public function __construct(Manager $manager, $namespace, WriteConcern $writeCon
7569 */
7670 public function __toString ()
7771 {
78- return $ this ->ns ;
72+ return $ this ->databaseName . ' . ' . $ this -> collectionName ;
7973 }
8074
8175 /**
@@ -95,7 +89,7 @@ public function aggregate(array $pipeline, array $options = array())
9589 {
9690 $ readPreference = new ReadPreference (ReadPreference::RP_PRIMARY );
9791 $ server = $ this ->manager ->selectServer ($ readPreference );
98- $ operation = new Aggregate ($ this ->dbname , $ this ->collname , $ pipeline , $ options );
92+ $ operation = new Aggregate ($ this ->databaseName , $ this ->collectionName , $ pipeline , $ options );
9993
10094 return $ operation ->execute ($ server );
10195 }
@@ -110,11 +104,11 @@ public function aggregate(array $pipeline, array $options = array())
110104 */
111105 public function bulkWrite (array $ operations , array $ options = array ())
112106 {
113- if ( ! isset ($ options ['writeConcern ' ]) && isset ($ this ->wc )) {
114- $ options ['writeConcern ' ] = $ this ->wc ;
107+ if ( ! isset ($ options ['writeConcern ' ]) && isset ($ this ->writeConcern )) {
108+ $ options ['writeConcern ' ] = $ this ->writeConcern ;
115109 }
116110
117- $ operation = new BulkWrite ($ this ->dbname , $ this ->collname , $ operations , $ options );
111+ $ operation = new BulkWrite ($ this ->databaseName , $ this ->collectionName , $ operations , $ options );
118112 $ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
119113
120114 return $ operation ->execute ($ server );
@@ -130,7 +124,7 @@ public function bulkWrite(array $operations, array $options = array())
130124 */
131125 public function count ($ filter = array (), array $ options = array ())
132126 {
133- $ operation = new Count ($ this ->dbname , $ this ->collname , $ filter , $ options );
127+ $ operation = new Count ($ this ->databaseName , $ this ->collectionName , $ filter , $ options );
134128 $ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
135129
136130 return $ operation ->execute ($ server );
@@ -175,7 +169,7 @@ public function createIndex($key, array $options = array())
175169 */
176170 public function createIndexes (array $ indexes )
177171 {
178- $ operation = new CreateIndexes ($ this ->dbname , $ this ->collname , $ indexes );
172+ $ operation = new CreateIndexes ($ this ->databaseName , $ this ->collectionName , $ indexes );
179173 $ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
180174
181175 return $ operation ->execute ($ server );
@@ -192,11 +186,11 @@ public function createIndexes(array $indexes)
192186 */
193187 public function deleteMany ($ filter , array $ options = array ())
194188 {
195- if ( ! isset ($ options ['writeConcern ' ]) && isset ($ this ->wc )) {
196- $ options ['writeConcern ' ] = $ this ->wc ;
189+ if ( ! isset ($ options ['writeConcern ' ]) && isset ($ this ->writeConcern )) {
190+ $ options ['writeConcern ' ] = $ this ->writeConcern ;
197191 }
198192
199- $ operation = new DeleteMany ($ this ->dbname , $ this ->collname , $ filter , $ options );
193+ $ operation = new DeleteMany ($ this ->databaseName , $ this ->collectionName , $ filter , $ options );
200194 $ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
201195
202196 return $ operation ->execute ($ server );
@@ -213,11 +207,11 @@ public function deleteMany($filter, array $options = array())
213207 */
214208 public function deleteOne ($ filter , array $ options = array ())
215209 {
216- if ( ! isset ($ options ['writeConcern ' ]) && isset ($ this ->wc )) {
217- $ options ['writeConcern ' ] = $ this ->wc ;
210+ if ( ! isset ($ options ['writeConcern ' ]) && isset ($ this ->writeConcern )) {
211+ $ options ['writeConcern ' ] = $ this ->writeConcern ;
218212 }
219213
220- $ operation = new DeleteOne ($ this ->dbname , $ this ->collname , $ filter , $ options );
214+ $ operation = new DeleteOne ($ this ->databaseName , $ this ->collectionName , $ filter , $ options );
221215 $ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
222216
223217 return $ operation ->execute ($ server );
@@ -234,7 +228,7 @@ public function deleteOne($filter, array $options = array())
234228 */
235229 public function distinct ($ fieldName , $ filter = array (), array $ options = array ())
236230 {
237- $ operation = new Distinct ($ this ->dbname , $ this ->collname , $ fieldName , $ filter , $ options );
231+ $ operation = new Distinct ($ this ->databaseName , $ this ->collectionName , $ fieldName , $ filter , $ options );
238232 $ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
239233
240234 return $ operation ->execute ($ server );
@@ -247,7 +241,7 @@ public function distinct($fieldName, $filter = array(), array $options = array()
247241 */
248242 public function drop ()
249243 {
250- $ operation = new DropCollection ($ this ->dbname , $ this ->collname );
244+ $ operation = new DropCollection ($ this ->databaseName , $ this ->collectionName );
251245 $ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
252246
253247 return $ operation ->execute ($ server );
@@ -268,7 +262,7 @@ public function dropIndex($indexName)
268262 throw new InvalidArgumentException ('dropIndexes() must be used to drop multiple indexes ' );
269263 }
270264
271- $ operation = new DropIndexes ($ this ->dbname , $ this ->collname , $ indexName );
265+ $ operation = new DropIndexes ($ this ->databaseName , $ this ->collectionName , $ indexName );
272266 $ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
273267
274268 return $ operation ->execute ($ server );
@@ -281,7 +275,7 @@ public function dropIndex($indexName)
281275 */
282276 public function dropIndexes ()
283277 {
284- $ operation = new DropIndexes ($ this ->dbname , $ this ->collname , '* ' );
278+ $ operation = new DropIndexes ($ this ->databaseName , $ this ->collectionName , '* ' );
285279 $ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
286280
287281 return $ operation ->execute ($ server );
@@ -298,7 +292,7 @@ public function dropIndexes()
298292 */
299293 public function find ($ filter = array (), array $ options = array ())
300294 {
301- $ operation = new Find ($ this ->dbname , $ this ->collname , $ filter , $ options );
295+ $ operation = new Find ($ this ->databaseName , $ this ->collectionName , $ filter , $ options );
302296 $ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
303297
304298 return $ operation ->execute ($ server );
@@ -315,7 +309,7 @@ public function find($filter = array(), array $options = array())
315309 */
316310 public function findOne ($ filter = array (), array $ options = array ())
317311 {
318- $ operation = new FindOne ($ this ->dbname , $ this ->collname , $ filter , $ options );
312+ $ operation = new FindOne ($ this ->databaseName , $ this ->collectionName , $ filter , $ options );
319313 $ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
320314
321315 return $ operation ->execute ($ server );
@@ -334,7 +328,7 @@ public function findOne($filter = array(), array $options = array())
334328 */
335329 public function findOneAndDelete ($ filter , array $ options = array ())
336330 {
337- $ operation = new FindOneAndDelete ($ this ->dbname , $ this ->collname , $ filter , $ options );
331+ $ operation = new FindOneAndDelete ($ this ->databaseName , $ this ->collectionName , $ filter , $ options );
338332 $ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
339333
340334 return $ operation ->execute ($ server );
@@ -357,7 +351,7 @@ public function findOneAndDelete($filter, array $options = array())
357351 */
358352 public function findOneAndReplace ($ filter , $ replacement , array $ options = array ())
359353 {
360- $ operation = new FindOneAndReplace ($ this ->dbname , $ this ->collname , $ filter , $ replacement , $ options );
354+ $ operation = new FindOneAndReplace ($ this ->databaseName , $ this ->collectionName , $ filter , $ replacement , $ options );
361355 $ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
362356
363357 return $ operation ->execute ($ server );
@@ -380,7 +374,7 @@ public function findOneAndReplace($filter, $replacement, array $options = array(
380374 */
381375 public function findOneAndUpdate ($ filter , $ update , array $ options = array ())
382376 {
383- $ operation = new FindOneAndUpdate ($ this ->dbname , $ this ->collname , $ filter , $ update , $ options );
377+ $ operation = new FindOneAndUpdate ($ this ->databaseName , $ this ->collectionName , $ filter , $ update , $ options );
384378 $ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
385379
386380 return $ operation ->execute ($ server );
@@ -393,7 +387,7 @@ public function findOneAndUpdate($filter, $update, array $options = array())
393387 */
394388 public function getCollectionName ()
395389 {
396- return $ this ->collname ;
390+ return $ this ->collectionName ;
397391 }
398392
399393 /**
@@ -403,7 +397,7 @@ public function getCollectionName()
403397 */
404398 public function getDatabaseName ()
405399 {
406- return $ this ->dbname ;
400+ return $ this ->databaseName ;
407401 }
408402
409403 /**
@@ -414,7 +408,7 @@ public function getDatabaseName()
414408 */
415409 public function getNamespace ()
416410 {
417- return $ this ->ns ;
411+ return $ this ->databaseName . ' . ' . $ this -> collectionName ;
418412 }
419413
420414 /**
@@ -428,11 +422,11 @@ public function getNamespace()
428422 */
429423 public function insertMany (array $ documents , array $ options = array ())
430424 {
431- if ( ! isset ($ options ['writeConcern ' ]) && isset ($ this ->wc )) {
432- $ options ['writeConcern ' ] = $ this ->wc ;
425+ if ( ! isset ($ options ['writeConcern ' ]) && isset ($ this ->writeConcern )) {
426+ $ options ['writeConcern ' ] = $ this ->writeConcern ;
433427 }
434428
435- $ operation = new InsertMany ($ this ->dbname , $ this ->collname , $ documents , $ options );
429+ $ operation = new InsertMany ($ this ->databaseName , $ this ->collectionName , $ documents , $ options );
436430 $ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
437431
438432 return $ operation ->execute ($ server );
@@ -449,11 +443,11 @@ public function insertMany(array $documents, array $options = array())
449443 */
450444 public function insertOne ($ document , array $ options = array ())
451445 {
452- if ( ! isset ($ options ['writeConcern ' ]) && isset ($ this ->wc )) {
453- $ options ['writeConcern ' ] = $ this ->wc ;
446+ if ( ! isset ($ options ['writeConcern ' ]) && isset ($ this ->writeConcern )) {
447+ $ options ['writeConcern ' ] = $ this ->writeConcern ;
454448 }
455449
456- $ operation = new InsertOne ($ this ->dbname , $ this ->collname , $ document , $ options );
450+ $ operation = new InsertOne ($ this ->databaseName , $ this ->collectionName , $ document , $ options );
457451 $ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
458452
459453 return $ operation ->execute ($ server );
@@ -467,7 +461,7 @@ public function insertOne($document, array $options = array())
467461 */
468462 public function listIndexes (array $ options = array ())
469463 {
470- $ operation = new ListIndexes ($ this ->dbname , $ this ->collname , $ options );
464+ $ operation = new ListIndexes ($ this ->databaseName , $ this ->collectionName , $ options );
471465 $ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
472466
473467 return $ operation ->execute ($ server );
@@ -485,11 +479,11 @@ public function listIndexes(array $options = array())
485479 */
486480 public function replaceOne ($ filter , $ replacement , array $ options = array ())
487481 {
488- if ( ! isset ($ options ['writeConcern ' ]) && isset ($ this ->wc )) {
489- $ options ['writeConcern ' ] = $ this ->wc ;
482+ if ( ! isset ($ options ['writeConcern ' ]) && isset ($ this ->writeConcern )) {
483+ $ options ['writeConcern ' ] = $ this ->writeConcern ;
490484 }
491485
492- $ operation = new ReplaceOne ($ this ->dbname , $ this ->collname , $ filter , $ replacement , $ options );
486+ $ operation = new ReplaceOne ($ this ->databaseName , $ this ->collectionName , $ filter , $ replacement , $ options );
493487 $ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
494488
495489 return $ operation ->execute ($ server );
@@ -507,11 +501,11 @@ public function replaceOne($filter, $replacement, array $options = array())
507501 */
508502 public function updateMany ($ filter , $ update , array $ options = array ())
509503 {
510- if ( ! isset ($ options ['writeConcern ' ]) && isset ($ this ->wc )) {
511- $ options ['writeConcern ' ] = $ this ->wc ;
504+ if ( ! isset ($ options ['writeConcern ' ]) && isset ($ this ->writeConcern )) {
505+ $ options ['writeConcern ' ] = $ this ->writeConcern ;
512506 }
513507
514- $ operation = new UpdateMany ($ this ->dbname , $ this ->collname , $ filter , $ update , $ options );
508+ $ operation = new UpdateMany ($ this ->databaseName , $ this ->collectionName , $ filter , $ update , $ options );
515509 $ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
516510
517511 return $ operation ->execute ($ server );
@@ -529,11 +523,11 @@ public function updateMany($filter, $update, array $options = array())
529523 */
530524 public function updateOne ($ filter , $ update , array $ options = array ())
531525 {
532- if ( ! isset ($ options ['writeConcern ' ]) && isset ($ this ->wc )) {
533- $ options ['writeConcern ' ] = $ this ->wc ;
526+ if ( ! isset ($ options ['writeConcern ' ]) && isset ($ this ->writeConcern )) {
527+ $ options ['writeConcern ' ] = $ this ->writeConcern ;
534528 }
535529
536- $ operation = new UpdateOne ($ this ->dbname , $ this ->collname , $ filter , $ update , $ options );
530+ $ operation = new UpdateOne ($ this ->databaseName , $ this ->collectionName , $ filter , $ update , $ options );
537531 $ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
538532
539533 return $ operation ->execute ($ server );
0 commit comments