Skip to content

Commit 2b93dab

Browse files
committed
Rename GridFSCollectionsWrapper to CollectionWrapper
1 parent 400e829 commit 2b93dab

File tree

5 files changed

+45
-45
lines changed

5 files changed

+45
-45
lines changed

src/GridFS/Bucket.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Bucket
2222
private static $streamWrapper;
2323
private static $defaultChunkSizeBytes = 261120;
2424

25-
private $collectionsWrapper;
25+
private $collectionWrapper;
2626
private $databaseName;
2727
private $options;
2828

@@ -74,7 +74,7 @@ public function __construct(Manager $manager, $databaseName, array $options = []
7474

7575
$collectionOptions = array_intersect_key($options, ['readPreference' => 1, 'writeConcern' => 1]);
7676

77-
$this->collectionsWrapper = new GridFSCollectionsWrapper($manager, $databaseName, $options['bucketName'], $collectionOptions);
77+
$this->collectionWrapper = new CollectionWrapper($manager, $databaseName, $options['bucketName'], $collectionOptions);
7878
$this->registerStreamWrapper($manager);
7979
}
8080

@@ -89,12 +89,12 @@ public function __construct(Manager $manager, $databaseName, array $options = []
8989
*/
9090
public function delete(ObjectId $id)
9191
{
92-
$file = $this->collectionsWrapper->getFilesCollection()->findOne(['_id' => $id]);
93-
$this->collectionsWrapper->getFilesCollection()->deleteOne(['_id' => $id]);
94-
$this->collectionsWrapper->getChunksCollection()->deleteMany(['files_id' => $id]);
92+
$file = $this->collectionWrapper->getFilesCollection()->findOne(['_id' => $id]);
93+
$this->collectionWrapper->getFilesCollection()->deleteOne(['_id' => $id]);
94+
$this->collectionWrapper->getChunksCollection()->deleteMany(['files_id' => $id]);
9595

9696
if ($file === null) {
97-
throw FileNotFoundException::byId($id, $this->collectionsWrapper->getFilesCollection()->getNameSpace());
97+
throw FileNotFoundException::byId($id, $this->collectionWrapper->getFilesCollection()->getNameSpace());
9898
}
9999

100100
}
@@ -108,16 +108,16 @@ public function delete(ObjectId $id)
108108
*/
109109
public function downloadToStream(ObjectId $id, $destination)
110110
{
111-
$file = $this->collectionsWrapper->getFilesCollection()->findOne(
111+
$file = $this->collectionWrapper->getFilesCollection()->findOne(
112112
['_id' => $id],
113113
['typeMap' => ['root' => 'stdClass']]
114114
);
115115

116116
if ($file === null) {
117-
throw FileNotFoundException::byId($id, $this->collectionsWrapper->getFilesCollection()->getNameSpace());
117+
throw FileNotFoundException::byId($id, $this->collectionWrapper->getFilesCollection()->getNameSpace());
118118
}
119119

120-
$gridFsStream = new GridFSDownload($this->collectionsWrapper, $file);
120+
$gridFsStream = new GridFSDownload($this->collectionWrapper, $file);
121121
$gridFsStream->downloadToStream($destination);
122122
}
123123

@@ -149,7 +149,7 @@ public function downloadToStreamByName($filename, $destination, array $options =
149149
{
150150
$options += ['revision' => -1];
151151
$file = $this->findFileRevision($filename, $options['revision']);
152-
$gridFsStream = new GridFSDownload($this->collectionsWrapper, $file);
152+
$gridFsStream = new GridFSDownload($this->collectionWrapper, $file);
153153
$gridFsStream->downloadToStream($destination);
154154
}
155155

@@ -160,7 +160,7 @@ public function downloadToStreamByName($filename, $destination, array $options =
160160

161161
public function drop()
162162
{
163-
$this->collectionsWrapper->dropCollections();
163+
$this->collectionWrapper->dropCollections();
164164
}
165165

166166
/**
@@ -173,12 +173,12 @@ public function drop()
173173
*/
174174
public function find($filter, array $options = [])
175175
{
176-
return $this->collectionsWrapper->getFilesCollection()->find($filter, $options);
176+
return $this->collectionWrapper->getFilesCollection()->find($filter, $options);
177177
}
178178

179179
public function getCollectionsWrapper()
180180
{
181-
return $this->collectionsWrapper;
181+
return $this->collectionWrapper;
182182
}
183183

184184
public function getDatabaseName()
@@ -212,13 +212,13 @@ public function getIdFromStream($stream)
212212
*/
213213
public function openDownloadStream(ObjectId $id)
214214
{
215-
$file = $this->collectionsWrapper->getFilesCollection()->findOne(
215+
$file = $this->collectionWrapper->getFilesCollection()->findOne(
216216
['_id' => $id],
217217
['typeMap' => ['root' => 'stdClass']]
218218
);
219219

220220
if ($file === null) {
221-
throw FileNotFoundException::byId($id, $this->collectionsWrapper->getFilesCollection()->getNameSpace());
221+
throw FileNotFoundException::byId($id, $this->collectionWrapper->getFilesCollection()->getNameSpace());
222222
}
223223

224224
return $this->openDownloadStreamByFile($file);
@@ -273,7 +273,7 @@ public function openUploadStream($filename, array $options = [])
273273
$options += ['chunkSizeBytes' => $this->options['chunkSizeBytes']];
274274

275275
$streamOptions = [
276-
'collectionsWrapper' => $this->collectionsWrapper,
276+
'collectionWrapper' => $this->collectionWrapper,
277277
'uploadOptions' => $options,
278278
];
279279

@@ -291,10 +291,10 @@ public function openUploadStream($filename, array $options = [])
291291
*/
292292
public function rename(ObjectId $id, $newFilename)
293293
{
294-
$filesCollection = $this->collectionsWrapper->getFilesCollection();
294+
$filesCollection = $this->collectionWrapper->getFilesCollection();
295295
$result = $filesCollection->updateOne(['_id' => $id], ['$set' => ['filename' => $newFilename]]);
296296
if($result->getModifiedCount() == 0) {
297-
throw FileNotFoundException::byId($id, $this->collectionsWrapper->getFilesCollection()->getNameSpace());
297+
throw FileNotFoundException::byId($id, $this->collectionWrapper->getFilesCollection()->getNameSpace());
298298
}
299299
}
300300

@@ -314,7 +314,7 @@ public function rename(ObjectId $id, $newFilename)
314314
public function uploadFromStream($filename, $source, array $options = [])
315315
{
316316
$options += ['chunkSizeBytes' => $this->options['chunkSizeBytes']];
317-
$gridFsStream = new GridFSUpload($this->collectionsWrapper, $filename, $options);
317+
$gridFsStream = new GridFSUpload($this->collectionWrapper, $filename, $options);
318318

319319
return $gridFsStream->uploadFromStream($source);
320320
}
@@ -329,7 +329,7 @@ private function findFileRevision($filename, $revision)
329329
$sortOrder = 1;
330330
}
331331

332-
$filesCollection = $this->collectionsWrapper->getFilesCollection();
332+
$filesCollection = $this->collectionWrapper->getFilesCollection();
333333
$file = $filesCollection->findOne(
334334
['filename' => $filename],
335335
[
@@ -349,7 +349,7 @@ private function findFileRevision($filename, $revision)
349349
private function openDownloadStreamByFile($file)
350350
{
351351
$options = [
352-
'collectionsWrapper' => $this->collectionsWrapper,
352+
'collectionWrapper' => $this->collectionWrapper,
353353
'file' => $file,
354354
];
355355

src/GridFS/GridFSCollectionsWrapper.php renamed to src/GridFS/CollectionWrapper.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
use MongoDB\Collection;
66
use MongoDB\Driver\Manager;
77
use MongoDB\Driver\ReadPreference;
8-
use MongoDB\Driver\WriteConcern;
98

109
/**
11-
* GridFSCollectionsWrapper abstracts the GridFS files and chunks collections.
10+
* CollectionWrapper abstracts the GridFS files and chunks collections.
1211
*
1312
* @internal
1413
*/
15-
class GridFSCollectionsWrapper
14+
class CollectionWrapper
1615
{
1716
private $chunksCollection;
1817
private $ensuredIndexes = false;
@@ -34,8 +33,9 @@ public function __construct(Manager $manager, $databaseName, $bucketName, array
3433
$this->chunksCollection = new Collection($manager, $databaseName, sprintf('%s.chunks', $bucketName), $collectionOptions);
3534
}
3635

37-
public function dropCollections(){
38-
$this->filesCollection-> drop();
36+
public function dropCollections()
37+
{
38+
$this->filesCollection->drop();
3939
$this->chunksCollection->drop();
4040
}
4141

src/GridFS/GridFSDownload.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class GridFSDownload
1919
private $bytesSeen = 0;
2020
private $chunkOffset = 0;
2121
private $chunksIterator;
22-
private $collectionsWrapper;
22+
private $collectionWrapper;
2323
private $file;
2424
private $firstCheck = true;
2525
private $iteratorEmpty = false;
@@ -28,17 +28,17 @@ class GridFSDownload
2828
/**
2929
* Constructs a GridFS download stream.
3030
*
31-
* @param GridFSCollectionsWrapper $collectionsWrapper GridFS collections wrapper
32-
* @param stdClass $file GridFS file document
31+
* @param CollectionWrapper $collectionWrapper GridFS collection wrapper
32+
* @param stdClass $file GridFS file document
3333
* @throws CorruptFileException
3434
*/
35-
public function __construct(GridFSCollectionsWrapper $collectionsWrapper, stdClass $file)
35+
public function __construct(CollectionWrapper $collectionWrapper, stdClass $file)
3636
{
37-
$this->collectionsWrapper = $collectionsWrapper;
37+
$this->collectionWrapper = $collectionWrapper;
3838
$this->file = $file;
3939

4040
try {
41-
$cursor = $this->collectionsWrapper->getChunksCollection()->find(
41+
$cursor = $this->collectionWrapper->getChunksCollection()->find(
4242
['files_id' => $this->file->_id],
4343
['sort' => ['n' => 1]]
4444
);

src/GridFS/GridFSUpload.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class GridFSUpload
1919
private $bufferLength = 0;
2020
private $chunkOffset = 0;
2121
private $chunkSize;
22-
private $collectionsWrapper;
22+
private $collectionWrapper;
2323
private $ctx;
2424
private $file;
2525
private $indexChecker;
@@ -44,12 +44,12 @@ class GridFSUpload
4444
* * metadata (document): User data for the "metadata" field of the files
4545
* collection document.
4646
*
47-
* @param GridFSCollectionsWrapper $collectionsWrapper GridFS collections wrapper
48-
* @param string $filename File name
49-
* @param array $options Upload options
47+
* @param CollectionWrapper $collectionWrapper GridFS collection wrapper
48+
* @param string $filename File name
49+
* @param array $options Upload options
5050
* @throws InvalidArgumentException
5151
*/
52-
public function __construct(GridFSCollectionsWrapper $collectionsWrapper, $filename, array $options = [])
52+
public function __construct(CollectionWrapper $collectionWrapper, $filename, array $options = [])
5353
{
5454
$options += ['chunkSizeBytes' => 261120];
5555

@@ -66,7 +66,7 @@ public function __construct(GridFSCollectionsWrapper $collectionsWrapper, $filen
6666
}
6767

6868
$this->chunkSize = $options['chunkSizeBytes'];
69-
$this->collectionsWrapper = $collectionsWrapper;
69+
$this->collectionWrapper = $collectionWrapper;
7070
$this->buffer = fopen('php://temp', 'w+');
7171
$this->ctx = hash_init('md5');
7272

@@ -189,8 +189,8 @@ public function uploadFromStream($source)
189189

190190
private function abort()
191191
{
192-
$this->collectionsWrapper->getChunksCollection()->deleteMany(['files_id' => $this->file['_id']]);
193-
$this->collectionsWrapper->getFilesCollection()->deleteOne(['_id' => $this->file['_id']]);
192+
$this->collectionWrapper->getChunksCollection()->deleteMany(['files_id' => $this->file['_id']]);
193+
$this->collectionWrapper->getFilesCollection()->deleteOne(['_id' => $this->file['_id']]);
194194
$this->isClosed = true;
195195
}
196196

@@ -215,7 +215,7 @@ private function fileCollectionInsert()
215215
$this->file['length'] = $this->length;
216216
$this->file['md5'] = $md5;
217217

218-
$this->collectionsWrapper->insertFile($this->file);
218+
$this->collectionWrapper->insertFile($this->file);
219219

220220
return $this->file['_id'];
221221
}
@@ -235,7 +235,7 @@ private function insertChunk($data)
235235

236236
hash_update($this->ctx, $data);
237237

238-
$this->collectionsWrapper->insertChunk($toUpload);
238+
$this->collectionWrapper->insertChunk($toUpload);
239239
$this->length += strlen($data);
240240
$this->chunkOffset++;
241241
}

src/GridFS/StreamWrapper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function getId()
2626
public function openReadStream()
2727
{
2828
$context = stream_context_get_options($this->context);
29-
$this->gridFSStream = new GridFSDownload($this->collectionsWrapper, $context['gridfs']['file']);
29+
$this->gridFSStream = new GridFSDownload($this->collectionWrapper, $context['gridfs']['file']);
3030
$this->id = $this->gridFSStream->getId();
3131

3232
return true;
@@ -36,7 +36,7 @@ public function openWriteStream()
3636
{
3737
$context = stream_context_get_options($this->context);
3838
$options = $context['gridfs']['uploadOptions'];
39-
$this->gridFSStream = new GridFSUpload($this->collectionsWrapper, $this->identifier, $options);
39+
$this->gridFSStream = new GridFSUpload($this->collectionWrapper, $this->identifier, $options);
4040
$this->id = $this->gridFSStream->getId();
4141

4242
return true;
@@ -68,7 +68,7 @@ public function stream_open($path, $mode, $options, &$openedPath)
6868
{
6969
$this->initProtocol($path);
7070
$context = stream_context_get_options($this->context);
71-
$this->collectionsWrapper = $context['gridfs']['collectionsWrapper'];
71+
$this->collectionWrapper = $context['gridfs']['collectionWrapper'];
7272
$this->mode = $mode;
7373

7474
switch ($this->mode) {

0 commit comments

Comments
 (0)