@@ -26,7 +26,8 @@ class Bucket
26
26
27
27
private $ collectionWrapper ;
28
28
private $ databaseName ;
29
- private $ options ;
29
+ private $ bucketName ;
30
+ private $ chunkSizeBytes ;
30
31
31
32
/**
32
33
* Constructs a GridFS bucket.
@@ -78,14 +79,30 @@ public function __construct(Manager $manager, $databaseName, array $options = []
78
79
}
79
80
80
81
$ this ->databaseName = (string ) $ databaseName ;
81
- $ this ->options = $ options ;
82
+ $ this ->bucketName = $ options ['bucketName ' ];
83
+ $ this ->chunkSizeBytes = $ options ['chunkSizeBytes ' ];
82
84
83
85
$ collectionOptions = array_intersect_key ($ options , ['readConcern ' => 1 , 'readPreference ' => 1 , 'writeConcern ' => 1 ]);
84
86
85
87
$ this ->collectionWrapper = new CollectionWrapper ($ manager , $ databaseName , $ options ['bucketName ' ], $ collectionOptions );
86
88
$ this ->registerStreamWrapper ();
87
89
}
88
90
91
+ /**
92
+ * Return internal properties for debugging purposes.
93
+ *
94
+ * @see http://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.debuginfo
95
+ * @return array
96
+ */
97
+ public function __debugInfo ()
98
+ {
99
+ return [
100
+ 'bucketName ' => $ this ->bucketName ,
101
+ 'databaseName ' => $ this ->databaseName ,
102
+ 'chunkSizeBytes ' => $ this ->chunkSizeBytes ,
103
+ ];
104
+ }
105
+
89
106
/**
90
107
* Delete a file from the GridFS bucket.
91
108
*
@@ -179,6 +196,21 @@ public function find($filter, array $options = [])
179
196
return $ this ->collectionWrapper ->findFiles ($ filter , $ options );
180
197
}
181
198
199
+ /**
200
+ * Return the bucket name.
201
+ *
202
+ * @return string
203
+ */
204
+ public function getBucketName ()
205
+ {
206
+ return $ this ->bucketName ;
207
+ }
208
+
209
+ /**
210
+ * Return the database name.
211
+ *
212
+ * @return string
213
+ */
182
214
public function getDatabaseName ()
183
215
{
184
216
return $ this ->databaseName ;
@@ -275,7 +307,7 @@ public function openDownloadStreamByName($filename, array $options = [])
275
307
*/
276
308
public function openUploadStream ($ filename , array $ options = [])
277
309
{
278
- $ options += ['chunkSizeBytes ' => $ this ->options [ ' chunkSizeBytes ' ] ];
310
+ $ options += ['chunkSizeBytes ' => $ this ->chunkSizeBytes ];
279
311
280
312
$ path = $ this ->createPathForUpload ();
281
313
$ context = stream_context_create ([
@@ -367,7 +399,7 @@ private function createPathForFile(stdClass $file)
367
399
'%s://%s/%s.files/%s ' ,
368
400
self ::$ streamWrapperProtocol ,
369
401
urlencode ($ this ->databaseName ),
370
- urlencode ($ this ->options [ ' bucketName ' ] ),
402
+ urlencode ($ this ->bucketName ),
371
403
urlencode ($ id )
372
404
);
373
405
}
@@ -383,7 +415,7 @@ private function createPathForUpload()
383
415
'%s://%s/%s.files ' ,
384
416
self ::$ streamWrapperProtocol ,
385
417
urlencode ($ this ->databaseName ),
386
- urlencode ($ this ->options [ ' bucketName ' ] )
418
+ urlencode ($ this ->bucketName )
387
419
);
388
420
}
389
421
@@ -394,7 +426,7 @@ private function createPathForUpload()
394
426
*/
395
427
private function getFilesNamespace ()
396
428
{
397
- return sprintf ('%s.%s.files ' , $ this ->databaseName , $ this ->options [ ' bucketName ' ] );
429
+ return sprintf ('%s.%s.files ' , $ this ->databaseName , $ this ->bucketName );
398
430
}
399
431
400
432
/**
0 commit comments