Skip to content

Commit 780fb6c

Browse files
committed
Merge pull request #407
2 parents 680c137 + a448b60 commit 780fb6c

File tree

6 files changed

+116
-0
lines changed

6 files changed

+116
-0
lines changed

docs/reference/class/MongoDBGridFSBucket.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ Methods
4242
/reference/method/MongoDBGridFSBucket-find
4343
/reference/method/MongoDBGridFSBucket-findOne
4444
/reference/method/MongoDBGridFSBucket-getBucketName
45+
/reference/method/MongoDBGridFSBucket-getChunksCollection
4546
/reference/method/MongoDBGridFSBucket-getChunkSizeBytes
4647
/reference/method/MongoDBGridFSBucket-getDatabaseName
4748
/reference/method/MongoDBGridFSBucket-getFileDocumentForStream
4849
/reference/method/MongoDBGridFSBucket-getFileIdForStream
50+
/reference/method/MongoDBGridFSBucket-getFilesCollection
4951
/reference/method/MongoDBGridFSBucket-getReadConcern
5052
/reference/method/MongoDBGridFSBucket-getReadPreference
5153
/reference/method/MongoDBGridFSBucket-getTypeMap
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
==============================================
2+
MongoDB\\GridFS\\Bucket::getChunksCollection()
3+
==============================================
4+
5+
.. default-domain:: mongodb
6+
7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 1
11+
:class: singlecol
12+
13+
Definition
14+
----------
15+
16+
.. phpmethod:: MongoDB\\GridFS\\Bucket::getChunksCollection()
17+
18+
Returns the chunks collection used by the bucket.
19+
20+
.. code-block:: php
21+
22+
function getChunksCollection(): MongoDB\Collection
23+
24+
Return Values
25+
-------------
26+
27+
A :phpclass:`MongoDB\\Collection` object for the chunks collection.
28+
29+
.. todo: add examples
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
=============================================
2+
MongoDB\\GridFS\\Bucket::getFilesCollection()
3+
=============================================
4+
5+
.. default-domain:: mongodb
6+
7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 1
11+
:class: singlecol
12+
13+
Definition
14+
----------
15+
16+
.. phpmethod:: MongoDB\\GridFS\\Bucket::getFilesCollection()
17+
18+
Returns the files collection used by the bucket.
19+
20+
.. code-block:: php
21+
22+
function getFilesCollection(): MongoDB\Collection
23+
24+
Return Values
25+
-------------
26+
27+
A :phpclass:`MongoDB\\Collection` object for the files collection.
28+
29+
.. todo: add examples

src/GridFS/Bucket.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,16 @@ public function getBucketName()
278278
return $this->bucketName;
279279
}
280280

281+
/**
282+
* Return the chunks collection.
283+
*
284+
* @return Collection
285+
*/
286+
public function getChunksCollection()
287+
{
288+
return $this->collectionWrapper->getChunksCollection();
289+
}
290+
281291
/**
282292
* Return the chunk size in bytes.
283293
*
@@ -340,6 +350,16 @@ public function getFileIdForStream($stream)
340350
return $file->_id;
341351
}
342352

353+
/**
354+
* Return the files collection.
355+
*
356+
* @return Collection
357+
*/
358+
public function getFilesCollection()
359+
{
360+
return $this->collectionWrapper->getFilesCollection();
361+
}
362+
343363
/**
344364
* Return the read concern for this GridFS bucket.
345365
*

src/GridFS/CollectionWrapper.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,16 @@ public function getBucketName()
197197
return $this->bucketName;
198198
}
199199

200+
/**
201+
* Return the chunks collection.
202+
*
203+
* @return Collection
204+
*/
205+
public function getChunksCollection()
206+
{
207+
return $this->chunksCollection;
208+
}
209+
200210
/**
201211
* Return the database name.
202212
*
@@ -207,6 +217,16 @@ public function getDatabaseName()
207217
return $this->databaseName;
208218
}
209219

220+
/**
221+
* Return the files collection.
222+
*
223+
* @return Collection
224+
*/
225+
public function getFilesCollection()
226+
{
227+
return $this->filesCollection;
228+
}
229+
210230
/**
211231
* Inserts a document into the chunks collection.
212232
*

tests/GridFS/BucketFunctionalTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,14 @@ public function testGetBucketNameWithDefaultValue()
363363
$this->assertEquals('fs', $this->bucket->getBucketName());
364364
}
365365

366+
public function testGetChunksCollection()
367+
{
368+
$chunksCollection = $this->bucket->getChunksCollection();
369+
370+
$this->assertInstanceOf('MongoDB\Collection', $chunksCollection);
371+
$this->assertEquals('fs.chunks', $chunksCollection->getCollectionName());
372+
}
373+
366374
public function testGetChunkSizeBytesWithCustomValue()
367375
{
368376
$bucket = new Bucket($this->manager, $this->getDatabaseName(), ['chunkSizeBytes' => 8192]);
@@ -466,6 +474,14 @@ public function testGetFileIdForStreamShouldRequireGridFSStreamResource($stream)
466474
$this->bucket->getFileIdForStream($stream);
467475
}
468476

477+
public function testGetFilesCollection()
478+
{
479+
$filesCollection = $this->bucket->getFilesCollection();
480+
481+
$this->assertInstanceOf('MongoDB\Collection', $filesCollection);
482+
$this->assertEquals('fs.files', $filesCollection->getCollectionName());
483+
}
484+
469485
/**
470486
* @dataProvider provideInputDataAndExpectedChunks
471487
*/

0 commit comments

Comments
 (0)