6262 */
6363class Bucket
6464{
65- /** @var string */
66- private static $ defaultBucketName = 'fs ' ;
65+ private const DEFAULT_BUCKET_NAME = 'fs ' ;
6766
68- /** @var integer */
69- private static $ defaultChunkSizeBytes = 261120 ;
67+ private const DEFAULT_CHUNK_SIZE_BYTES = 261120 ;
7068
71- /** @var array */
72- private static $ defaultTypeMap = [
69+ private const DEFAULT_TYPE_MAP = [
7370 'array ' => BSONArray::class,
7471 'document ' => BSONDocument::class,
7572 'root ' => BSONDocument::class,
7673 ];
7774
78- /** @var string */
79- private static $ streamWrapperProtocol = 'gridfs ' ;
75+ private const STREAM_WRAPPER_PROTOCOL = 'gridfs ' ;
8076
8177 /** @var CollectionWrapper */
8278 private $ collectionWrapper ;
@@ -138,8 +134,8 @@ class Bucket
138134 public function __construct (Manager $ manager , string $ databaseName , array $ options = [])
139135 {
140136 $ options += [
141- 'bucketName ' => self ::$ defaultBucketName ,
142- 'chunkSizeBytes ' => self ::$ defaultChunkSizeBytes ,
137+ 'bucketName ' => self ::DEFAULT_BUCKET_NAME ,
138+ 'chunkSizeBytes ' => self ::DEFAULT_CHUNK_SIZE_BYTES ,
143139 'disableMD5 ' => false ,
144140 ];
145141
@@ -182,7 +178,7 @@ public function __construct(Manager $manager, string $databaseName, array $optio
182178 $ this ->disableMD5 = $ options ['disableMD5 ' ];
183179 $ this ->readConcern = $ options ['readConcern ' ] ?? $ this ->manager ->getReadConcern ();
184180 $ this ->readPreference = $ options ['readPreference ' ] ?? $ this ->manager ->getReadPreference ();
185- $ this ->typeMap = $ options ['typeMap ' ] ?? self ::$ defaultTypeMap ;
181+ $ this ->typeMap = $ options ['typeMap ' ] ?? self ::DEFAULT_TYPE_MAP ;
186182 $ this ->writeConcern = $ options ['writeConcern ' ] ?? $ this ->manager ->getWriteConcern ();
187183
188184 $ collectionOptions = array_intersect_key ($ options , ['readConcern ' => 1 , 'readPreference ' => 1 , 'typeMap ' => 1 , 'writeConcern ' => 1 ]);
@@ -555,7 +551,7 @@ public function openUploadStream(string $filename, array $options = [])
555551
556552 $ path = $ this ->createPathForUpload ();
557553 $ context = stream_context_create ([
558- self ::$ streamWrapperProtocol => [
554+ self ::STREAM_WRAPPER_PROTOCOL => [
559555 'collectionWrapper ' => $ this ->collectionWrapper ,
560556 'filename ' => $ filename ,
561557 'options ' => $ options ,
@@ -651,7 +647,7 @@ private function createPathForFile(object $file): string
651647
652648 return sprintf (
653649 '%s://%s/%s.files/%s ' ,
654- self ::$ streamWrapperProtocol ,
650+ self ::STREAM_WRAPPER_PROTOCOL ,
655651 urlencode ($ this ->databaseName ),
656652 urlencode ($ this ->bucketName ),
657653 urlencode ($ id )
@@ -665,7 +661,7 @@ private function createPathForUpload(): string
665661 {
666662 return sprintf (
667663 '%s://%s/%s.files ' ,
668- self ::$ streamWrapperProtocol ,
664+ self ::STREAM_WRAPPER_PROTOCOL ,
669665 urlencode ($ this ->databaseName ),
670666 urlencode ($ this ->bucketName )
671667 );
@@ -713,7 +709,7 @@ private function openDownloadStreamByFile(object $file)
713709 {
714710 $ path = $ this ->createPathForFile ($ file );
715711 $ context = stream_context_create ([
716- self ::$ streamWrapperProtocol => [
712+ self ::STREAM_WRAPPER_PROTOCOL => [
717713 'collectionWrapper ' => $ this ->collectionWrapper ,
718714 'file ' => $ file ,
719715 ],
@@ -727,10 +723,10 @@ private function openDownloadStreamByFile(object $file)
727723 */
728724 private function registerStreamWrapper (): void
729725 {
730- if (in_array (self ::$ streamWrapperProtocol , stream_get_wrappers ())) {
726+ if (in_array (self ::STREAM_WRAPPER_PROTOCOL , stream_get_wrappers ())) {
731727 return ;
732728 }
733729
734- StreamWrapper::register (self ::$ streamWrapperProtocol );
730+ StreamWrapper::register (self ::STREAM_WRAPPER_PROTOCOL );
735731 }
736732}
0 commit comments