Phalcon\Db\Adapter\MongoDB\GridFS\WritableStream::__construct PHP Method

__construct() public method

Supported options: * _id (mixed): File document identifier. Defaults to a new ObjectId. * aliases (array of strings): DEPRECATED An array of aliases. Applications wishing to store aliases should add an aliases field to the metadata document instead. * chunkSizeBytes (integer): The chunk size in bytes. Defaults to 261120 (i.e. 255 KiB). * contentType (string): DEPRECATED content type to be stored with the file. This information should now be added to the metadata. * metadata (document): User data for the "metadata" field of the files collection document.
public __construct ( CollectionWrapper $collectionWrapper, string $filename, array $options = [] )
$collectionWrapper CollectionWrapper GridFS collection wrapper
$filename string Filename
$options array Upload options
    public function __construct(CollectionWrapper $collectionWrapper, $filename, array $options = [])
    {
        $options += ['_id' => new ObjectId(), 'chunkSizeBytes' => self::$defaultChunkSizeBytes];
        if (isset($options['aliases']) && !Functions::isStringArray($options['aliases'])) {
            throw InvalidArgumentException::invalidType('"aliases" option', $options['aliases'], 'array of strings');
        }
        if (isset($options['chunkSizeBytes']) && !is_integer($options['chunkSizeBytes'])) {
            throw InvalidArgumentException::invalidType('"chunkSizeBytes" option', $options['chunkSizeBytes'], 'integer');
        }
        if (isset($options['contentType']) && !is_string($options['contentType'])) {
            throw InvalidArgumentException::invalidType('"contentType" option', $options['contentType'], 'string');
        }
        if (isset($options['metadata']) && !is_array($options['metadata']) && !is_object($options['metadata'])) {
            throw InvalidArgumentException::invalidType('"metadata" option', $options['metadata'], 'array or object');
        }
        $this->chunkSize = $options['chunkSizeBytes'];
        $this->collectionWrapper = $collectionWrapper;
        $this->buffer = fopen('php://temp', 'w+');
        $this->ctx = hash_init('md5');
        $this->file = ['_id' => $options['_id'], 'chunkSize' => $this->chunkSize, 'filename' => (string) $filename, 'uploadDate' => new UTCDateTime(floor(microtime(true) * 1000))] + array_intersect_key($options, ['aliases' => 1, 'contentType' => 1, 'metadata' => 1]);
    }