Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401]

(no description)

File Size: 727 lines (24 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: Bucket  - X-Ref

Bucket provides a public API for interacting with the GridFS files and chunks
collections.

__construct(Manager $manager, $databaseName, array $options = [])   X-Ref
Constructs a GridFS bucket.

Supported options:

* bucketName (string): The bucket name, which will be used as a prefix
for the files and chunks collections. Defaults to "fs".

* chunkSizeBytes (integer): The chunk size in bytes. Defaults to
261120 (i.e. 255 KiB).

* disableMD5 (boolean): When true, no MD5 sum will be generated for
each stored file. Defaults to "false".

* readConcern (MongoDB\Driver\ReadConcern): Read concern.

* readPreference (MongoDB\Driver\ReadPreference): Read preference.

* typeMap (array): Default type map for cursors and BSON documents.

* writeConcern (MongoDB\Driver\WriteConcern): Write concern.

param: Manager $manager      Manager instance from the driver
param: string  $databaseName Database name
param: array   $options      Bucket options

__debugInfo()   X-Ref
Return internal properties for debugging purposes.

return: array

delete($id)   X-Ref
Delete a file from the GridFS bucket.

If the files collection document is not found, this method will still
attempt to delete orphaned chunks.

param: mixed $id File ID

downloadToStream($id, $destination)   X-Ref
Writes the contents of a GridFS file to a writable stream.

param: mixed    $id          File ID
param: resource $destination Writable Stream

downloadToStreamByName($filename, $destination, array $options = [])   X-Ref
Writes the contents of a GridFS file, which is selected by name and
revision, to a writable stream.

Supported options:

* revision (integer): Which revision (i.e. documents with the same
filename and different uploadDate) of the file to retrieve. Defaults
to -1 (i.e. the most recent revision).

Revision numbers are defined as follows:

* 0 = the original stored file
* 1 = the first revision
* 2 = the second revision
* etc…
* -2 = the second most recent revision
* -1 = the most recent revision

param: string   $filename    Filename
param: resource $destination Writable Stream
param: array    $options     Download options

drop()   X-Ref
Drops the files and chunks collections associated with this GridFS
bucket.


find($filter = [], array $options = [])   X-Ref
Finds documents from the GridFS bucket's files collection matching the
query.

param: array|object $filter  Query by which to filter documents
param: array        $options Additional options
return: Cursor

findOne($filter = [], array $options = [])   X-Ref
Finds a single document from the GridFS bucket's files collection
matching the query.

param: array|object $filter  Query by which to filter documents
param: array        $options Additional options
return: array|object|null

getBucketName()   X-Ref
Return the bucket name.

return: string

getChunksCollection()   X-Ref
Return the chunks collection.

return: Collection

getChunkSizeBytes()   X-Ref
Return the chunk size in bytes.

return: integer

getDatabaseName()   X-Ref
Return the database name.

return: string

getFileDocumentForStream($stream)   X-Ref
Gets the file document of the GridFS file associated with a stream.

param: resource $stream GridFS stream
return: array|object

getFileIdForStream($stream)   X-Ref
Gets the file document's ID of the GridFS file associated with a stream.

param: resource $stream GridFS stream
return: mixed

getFilesCollection()   X-Ref
Return the files collection.

return: Collection

getReadConcern()   X-Ref
Return the read concern for this GridFS bucket.

return: ReadConcern

getReadPreference()   X-Ref
Return the read preference for this GridFS bucket.

return: ReadPreference

getTypeMap()   X-Ref
Return the type map for this GridFS bucket.

return: array

getWriteConcern()   X-Ref
Return the write concern for this GridFS bucket.

return: WriteConcern

openDownloadStream($id)   X-Ref
Opens a readable stream for reading a GridFS file.

param: mixed $id File ID
return: resource

openDownloadStreamByName($filename, array $options = [])   X-Ref
Opens a readable stream stream to read a GridFS file, which is selected
by name and revision.

Supported options:

* revision (integer): Which revision (i.e. documents with the same
filename and different uploadDate) of the file to retrieve. Defaults
to -1 (i.e. the most recent revision).

Revision numbers are defined as follows:

* 0 = the original stored file
* 1 = the first revision
* 2 = the second revision
* etc…
* -2 = the second most recent revision
* -1 = the most recent revision

param: string $filename Filename
param: array  $options  Download options
return: resource

openUploadStream($filename, array $options = [])   X-Ref
Opens a writable stream for writing a GridFS file.

Supported options:

* _id (mixed): File document identifier. Defaults to a new ObjectId.

* chunkSizeBytes (integer): The chunk size in bytes. Defaults to the
bucket's chunk size.

* disableMD5 (boolean): When true, no MD5 sum will be generated for
the stored file. Defaults to "false".

* metadata (document): User data for the "metadata" field of the files
collection document.

param: string $filename Filename
param: array  $options  Upload options
return: resource

rename($id, $newFilename)   X-Ref
Renames the GridFS file with the specified ID.

param: mixed  $id          File ID
param: string $newFilename New filename

uploadFromStream($filename, $source, array $options = [])   X-Ref
Writes the contents of a readable stream to a GridFS file.

Supported options:

* _id (mixed): File document identifier. Defaults to a new ObjectId.

* chunkSizeBytes (integer): The chunk size in bytes. Defaults to the
bucket's chunk size.

* disableMD5 (boolean): When true, no MD5 sum will be generated for
the stored file. Defaults to "false".

* metadata (document): User data for the "metadata" field of the files
collection document.

param: string   $filename Filename
param: resource $source   Readable stream
param: array    $options  Stream options
return: mixed ID of the newly created GridFS file

createPathForFile(stdClass $file)   X-Ref
Creates a path for an existing GridFS file.

param: stdClass $file GridFS file document
return: string

createPathForUpload()   X-Ref
Creates a path for a new GridFS file, which does not yet have an ID.

return: string

getFilesNamespace()   X-Ref
Returns the names of the files collection.

return: string

getRawFileDocumentForStream($stream)   X-Ref
Gets the file document of the GridFS file associated with a stream.

This returns the raw document from the StreamWrapper, which does not
respect the Bucket's type map.

param: resource $stream GridFS stream
return: stdClass

openDownloadStreamByFile(stdClass $file)   X-Ref
Opens a readable stream for the GridFS file.

param: stdClass $file GridFS file document
return: resource

registerStreamWrapper()   X-Ref
Registers the GridFS stream wrapper if it is not already registered.