36
36
37
37
class Collection
38
38
{
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 ;
49
44
50
45
/**
51
46
* Constructs new Collection instance.
@@ -61,11 +56,10 @@ class Collection
61
56
public function __construct (Manager $ manager , $ namespace , WriteConcern $ writeConcern = null , ReadPreference $ readPreference = null )
62
57
{
63
58
$ this ->manager = $ manager ;
64
- $ this ->ns = (string ) $ namespace ;
65
- $ this ->wc = $ writeConcern ;
66
- $ this ->rp = $ readPreference ;
59
+ $ this ->writeConcern = $ writeConcern ;
60
+ $ this ->readPreference = $ readPreference ;
67
61
68
- list ($ this ->dbname , $ this ->collname ) = explode (". " , $ namespace , 2 );
62
+ list ($ this ->databaseName , $ this ->collectionName ) = explode (". " , $ namespace , 2 );
69
63
}
70
64
71
65
/**
@@ -75,7 +69,7 @@ public function __construct(Manager $manager, $namespace, WriteConcern $writeCon
75
69
*/
76
70
public function __toString ()
77
71
{
78
- return $ this ->ns ;
72
+ return $ this ->databaseName . ' . ' . $ this -> collectionName ;
79
73
}
80
74
81
75
/**
@@ -95,7 +89,7 @@ public function aggregate(array $pipeline, array $options = array())
95
89
{
96
90
$ readPreference = new ReadPreference (ReadPreference::RP_PRIMARY );
97
91
$ 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 );
99
93
100
94
return $ operation ->execute ($ server );
101
95
}
@@ -110,11 +104,11 @@ public function aggregate(array $pipeline, array $options = array())
110
104
*/
111
105
public function bulkWrite (array $ operations , array $ options = array ())
112
106
{
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 ;
115
109
}
116
110
117
- $ operation = new BulkWrite ($ this ->dbname , $ this ->collname , $ operations , $ options );
111
+ $ operation = new BulkWrite ($ this ->databaseName , $ this ->collectionName , $ operations , $ options );
118
112
$ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
119
113
120
114
return $ operation ->execute ($ server );
@@ -130,7 +124,7 @@ public function bulkWrite(array $operations, array $options = array())
130
124
*/
131
125
public function count ($ filter = array (), array $ options = array ())
132
126
{
133
- $ operation = new Count ($ this ->dbname , $ this ->collname , $ filter , $ options );
127
+ $ operation = new Count ($ this ->databaseName , $ this ->collectionName , $ filter , $ options );
134
128
$ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
135
129
136
130
return $ operation ->execute ($ server );
@@ -175,7 +169,7 @@ public function createIndex($key, array $options = array())
175
169
*/
176
170
public function createIndexes (array $ indexes )
177
171
{
178
- $ operation = new CreateIndexes ($ this ->dbname , $ this ->collname , $ indexes );
172
+ $ operation = new CreateIndexes ($ this ->databaseName , $ this ->collectionName , $ indexes );
179
173
$ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
180
174
181
175
return $ operation ->execute ($ server );
@@ -192,11 +186,11 @@ public function createIndexes(array $indexes)
192
186
*/
193
187
public function deleteMany ($ filter , array $ options = array ())
194
188
{
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 ;
197
191
}
198
192
199
- $ operation = new DeleteMany ($ this ->dbname , $ this ->collname , $ filter , $ options );
193
+ $ operation = new DeleteMany ($ this ->databaseName , $ this ->collectionName , $ filter , $ options );
200
194
$ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
201
195
202
196
return $ operation ->execute ($ server );
@@ -213,11 +207,11 @@ public function deleteMany($filter, array $options = array())
213
207
*/
214
208
public function deleteOne ($ filter , array $ options = array ())
215
209
{
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 ;
218
212
}
219
213
220
- $ operation = new DeleteOne ($ this ->dbname , $ this ->collname , $ filter , $ options );
214
+ $ operation = new DeleteOne ($ this ->databaseName , $ this ->collectionName , $ filter , $ options );
221
215
$ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
222
216
223
217
return $ operation ->execute ($ server );
@@ -234,7 +228,7 @@ public function deleteOne($filter, array $options = array())
234
228
*/
235
229
public function distinct ($ fieldName , $ filter = array (), array $ options = array ())
236
230
{
237
- $ operation = new Distinct ($ this ->dbname , $ this ->collname , $ fieldName , $ filter , $ options );
231
+ $ operation = new Distinct ($ this ->databaseName , $ this ->collectionName , $ fieldName , $ filter , $ options );
238
232
$ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
239
233
240
234
return $ operation ->execute ($ server );
@@ -247,7 +241,7 @@ public function distinct($fieldName, $filter = array(), array $options = array()
247
241
*/
248
242
public function drop ()
249
243
{
250
- $ operation = new DropCollection ($ this ->dbname , $ this ->collname );
244
+ $ operation = new DropCollection ($ this ->databaseName , $ this ->collectionName );
251
245
$ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
252
246
253
247
return $ operation ->execute ($ server );
@@ -268,7 +262,7 @@ public function dropIndex($indexName)
268
262
throw new InvalidArgumentException ('dropIndexes() must be used to drop multiple indexes ' );
269
263
}
270
264
271
- $ operation = new DropIndexes ($ this ->dbname , $ this ->collname , $ indexName );
265
+ $ operation = new DropIndexes ($ this ->databaseName , $ this ->collectionName , $ indexName );
272
266
$ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
273
267
274
268
return $ operation ->execute ($ server );
@@ -281,7 +275,7 @@ public function dropIndex($indexName)
281
275
*/
282
276
public function dropIndexes ()
283
277
{
284
- $ operation = new DropIndexes ($ this ->dbname , $ this ->collname , '* ' );
278
+ $ operation = new DropIndexes ($ this ->databaseName , $ this ->collectionName , '* ' );
285
279
$ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
286
280
287
281
return $ operation ->execute ($ server );
@@ -298,7 +292,7 @@ public function dropIndexes()
298
292
*/
299
293
public function find ($ filter = array (), array $ options = array ())
300
294
{
301
- $ operation = new Find ($ this ->dbname , $ this ->collname , $ filter , $ options );
295
+ $ operation = new Find ($ this ->databaseName , $ this ->collectionName , $ filter , $ options );
302
296
$ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
303
297
304
298
return $ operation ->execute ($ server );
@@ -315,7 +309,7 @@ public function find($filter = array(), array $options = array())
315
309
*/
316
310
public function findOne ($ filter = array (), array $ options = array ())
317
311
{
318
- $ operation = new FindOne ($ this ->dbname , $ this ->collname , $ filter , $ options );
312
+ $ operation = new FindOne ($ this ->databaseName , $ this ->collectionName , $ filter , $ options );
319
313
$ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
320
314
321
315
return $ operation ->execute ($ server );
@@ -334,7 +328,7 @@ public function findOne($filter = array(), array $options = array())
334
328
*/
335
329
public function findOneAndDelete ($ filter , array $ options = array ())
336
330
{
337
- $ operation = new FindOneAndDelete ($ this ->dbname , $ this ->collname , $ filter , $ options );
331
+ $ operation = new FindOneAndDelete ($ this ->databaseName , $ this ->collectionName , $ filter , $ options );
338
332
$ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
339
333
340
334
return $ operation ->execute ($ server );
@@ -357,7 +351,7 @@ public function findOneAndDelete($filter, array $options = array())
357
351
*/
358
352
public function findOneAndReplace ($ filter , $ replacement , array $ options = array ())
359
353
{
360
- $ operation = new FindOneAndReplace ($ this ->dbname , $ this ->collname , $ filter , $ replacement , $ options );
354
+ $ operation = new FindOneAndReplace ($ this ->databaseName , $ this ->collectionName , $ filter , $ replacement , $ options );
361
355
$ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
362
356
363
357
return $ operation ->execute ($ server );
@@ -380,7 +374,7 @@ public function findOneAndReplace($filter, $replacement, array $options = array(
380
374
*/
381
375
public function findOneAndUpdate ($ filter , $ update , array $ options = array ())
382
376
{
383
- $ operation = new FindOneAndUpdate ($ this ->dbname , $ this ->collname , $ filter , $ update , $ options );
377
+ $ operation = new FindOneAndUpdate ($ this ->databaseName , $ this ->collectionName , $ filter , $ update , $ options );
384
378
$ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
385
379
386
380
return $ operation ->execute ($ server );
@@ -393,7 +387,7 @@ public function findOneAndUpdate($filter, $update, array $options = array())
393
387
*/
394
388
public function getCollectionName ()
395
389
{
396
- return $ this ->collname ;
390
+ return $ this ->collectionName ;
397
391
}
398
392
399
393
/**
@@ -403,7 +397,7 @@ public function getCollectionName()
403
397
*/
404
398
public function getDatabaseName ()
405
399
{
406
- return $ this ->dbname ;
400
+ return $ this ->databaseName ;
407
401
}
408
402
409
403
/**
@@ -414,7 +408,7 @@ public function getDatabaseName()
414
408
*/
415
409
public function getNamespace ()
416
410
{
417
- return $ this ->ns ;
411
+ return $ this ->databaseName . ' . ' . $ this -> collectionName ;
418
412
}
419
413
420
414
/**
@@ -428,11 +422,11 @@ public function getNamespace()
428
422
*/
429
423
public function insertMany (array $ documents , array $ options = array ())
430
424
{
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 ;
433
427
}
434
428
435
- $ operation = new InsertMany ($ this ->dbname , $ this ->collname , $ documents , $ options );
429
+ $ operation = new InsertMany ($ this ->databaseName , $ this ->collectionName , $ documents , $ options );
436
430
$ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
437
431
438
432
return $ operation ->execute ($ server );
@@ -449,11 +443,11 @@ public function insertMany(array $documents, array $options = array())
449
443
*/
450
444
public function insertOne ($ document , array $ options = array ())
451
445
{
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 ;
454
448
}
455
449
456
- $ operation = new InsertOne ($ this ->dbname , $ this ->collname , $ document , $ options );
450
+ $ operation = new InsertOne ($ this ->databaseName , $ this ->collectionName , $ document , $ options );
457
451
$ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
458
452
459
453
return $ operation ->execute ($ server );
@@ -467,7 +461,7 @@ public function insertOne($document, array $options = array())
467
461
*/
468
462
public function listIndexes (array $ options = array ())
469
463
{
470
- $ operation = new ListIndexes ($ this ->dbname , $ this ->collname , $ options );
464
+ $ operation = new ListIndexes ($ this ->databaseName , $ this ->collectionName , $ options );
471
465
$ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
472
466
473
467
return $ operation ->execute ($ server );
@@ -485,11 +479,11 @@ public function listIndexes(array $options = array())
485
479
*/
486
480
public function replaceOne ($ filter , $ replacement , array $ options = array ())
487
481
{
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 ;
490
484
}
491
485
492
- $ operation = new ReplaceOne ($ this ->dbname , $ this ->collname , $ filter , $ replacement , $ options );
486
+ $ operation = new ReplaceOne ($ this ->databaseName , $ this ->collectionName , $ filter , $ replacement , $ options );
493
487
$ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
494
488
495
489
return $ operation ->execute ($ server );
@@ -507,11 +501,11 @@ public function replaceOne($filter, $replacement, array $options = array())
507
501
*/
508
502
public function updateMany ($ filter , $ update , array $ options = array ())
509
503
{
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 ;
512
506
}
513
507
514
- $ operation = new UpdateMany ($ this ->dbname , $ this ->collname , $ filter , $ update , $ options );
508
+ $ operation = new UpdateMany ($ this ->databaseName , $ this ->collectionName , $ filter , $ update , $ options );
515
509
$ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
516
510
517
511
return $ operation ->execute ($ server );
@@ -529,11 +523,11 @@ public function updateMany($filter, $update, array $options = array())
529
523
*/
530
524
public function updateOne ($ filter , $ update , array $ options = array ())
531
525
{
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 ;
534
528
}
535
529
536
- $ operation = new UpdateOne ($ this ->dbname , $ this ->collname , $ filter , $ update , $ options );
530
+ $ operation = new UpdateOne ($ this ->databaseName , $ this ->collectionName , $ filter , $ update , $ options );
537
531
$ server = $ this ->manager ->selectServer (new ReadPreference (ReadPreference::RP_PRIMARY ));
538
532
539
533
return $ operation ->execute ($ server );
0 commit comments