Commit 5e1ce36b authored by Katherine Walker's avatar Katherine Walker

Merge branch 'v1.3'

parents 0c09ed1f f812b9e6
...@@ -37,4 +37,19 @@ Behavior ...@@ -37,4 +37,19 @@ Behavior
If the files collection document is not found, this method will still attempt to If the files collection document is not found, this method will still attempt to
delete orphaned chunks. delete orphaned chunks.
.. todo: add examples Examples
--------
.. code-block:: php
<?php
$bucket = (new MongoDB\Client)->test->selectGridFSBucket();
$stream = fopen('php://temp', 'w+b');
fwrite($stream, "foobar");
rewind($stream);
$id = $bucket->uploadFromStream('filename', $stream);
$bucket->delete($id);
...@@ -26,8 +26,6 @@ Definition ...@@ -26,8 +26,6 @@ Definition
.. include:: /includes/apiargs/MongoDBGridFSBucket-method-downloadToStream-param.rst .. include:: /includes/apiargs/MongoDBGridFSBucket-method-downloadToStream-param.rst
.. todo: add examples
Errors/Exceptions Errors/Exceptions
----------------- -----------------
...@@ -35,6 +33,31 @@ Errors/Exceptions ...@@ -35,6 +33,31 @@ Errors/Exceptions
.. include:: /includes/extracts/error-invalidargumentexception.rst .. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst .. include:: /includes/extracts/error-driver-runtimeexception.rst
Examples
--------
.. code-block:: php
<?php
$bucket = (new MongoDB\Client)->test->selectGridFSBucket();
$stream = fopen('php://temp', 'w+b');
fwrite($stream, "foobar");
rewind($stream);
$id = $bucket->uploadFromStream('filename', $stream);
$destination = fopen('php://temp', 'w+b');
$bucket->downloadToStream($id, $destination);
var_dump(stream_get_contents($destination, -1, 0));
The output would then resemble::
string(6) "foobar"
See Also See Also
-------- --------
......
...@@ -30,8 +30,6 @@ Definition ...@@ -30,8 +30,6 @@ Definition
.. include:: /includes/apiargs/MongoDBGridFSBucket-method-downloadToStreamByName-option.rst .. include:: /includes/apiargs/MongoDBGridFSBucket-method-downloadToStreamByName-option.rst
.. todo: add examples
Errors/Exceptions Errors/Exceptions
----------------- -----------------
...@@ -39,6 +37,31 @@ Errors/Exceptions ...@@ -39,6 +37,31 @@ Errors/Exceptions
.. include:: /includes/extracts/error-invalidargumentexception.rst .. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst .. include:: /includes/extracts/error-driver-runtimeexception.rst
Examples
--------
.. code-block:: php
<?php
$bucket = (new MongoDB\Client)->test->selectGridFSBucket();
$stream = fopen('php://temp', 'w+b');
fwrite($stream, "foobar");
rewind($stream);
$bucket->uploadFromStream('filename', $stream);
$destination = fopen('php://temp', 'w+b');
$bucket->downloadToStreamByName('filename', $destination);
var_dump(stream_get_contents($destination, -1, 0));
The output would then resemble::
string(6) "foobar"
See Also See Also
-------- --------
......
...@@ -26,4 +26,21 @@ Errors/Exceptions ...@@ -26,4 +26,21 @@ Errors/Exceptions
.. include:: /includes/extracts/error-driver-runtimeexception.rst .. include:: /includes/extracts/error-driver-runtimeexception.rst
.. todo: add examples Examples
--------
.. code-block:: php
<?php
$database = (new MongoDB\Client)->test;
$bucket = $database->selectGridFSBucket();
$stream = fopen('php://temp', 'w+b');
fwrite($stream, "foobar");
rewind($stream);
$bucket->uploadFromStream('filename', $stream);
$bucket->drop();
...@@ -46,7 +46,49 @@ Behavior ...@@ -46,7 +46,49 @@ Behavior
.. include:: /includes/extracts/note-bson-comparison.rst .. include:: /includes/extracts/note-bson-comparison.rst
.. todo: add examples Examples
--------
.. code-block:: php
<?php
$bucket = (new MongoDB\Client)->test->selectGridFSBucket();
$stream = fopen('php://temp', 'w+b');
fwrite($stream, "foobar");
rewind($stream);
$bucket->uploadFromStream('b', $stream);
$cursor = $bucket->find(
['length' => ['$lte' => 6]],
[
'projection' => [
'filename' => 1,
'length' => 1,
'_id' => 0,
],
'sort' => ['length' => -1],
]
);
var_dump($cursor->toArray());
The output would then resemble::
array(1) {
[0]=>
object(MongoDB\Model\BSONDocument)#3015 (1) {
["storage":"ArrayObject":private]=>
array(2) {
["filename"]=>
string(1) "b"
["length"]=>
int(6)
}
}
}
See Also See Also
-------- --------
......
...@@ -49,7 +49,46 @@ Behavior ...@@ -49,7 +49,46 @@ Behavior
.. include:: /includes/extracts/note-bson-comparison.rst .. include:: /includes/extracts/note-bson-comparison.rst
.. todo: add examples Examples
--------
.. code-block:: php
<?php
$bucket = (new MongoDB\Client)->test->selectGridFSBucket();
$stream = fopen('php://temp', 'w+b');
fwrite($stream, "foobar");
rewind($stream);
$bucket->uploadFromStream('b', $stream);
$fileDocument = $bucket->findOne(
['length' => ['$lte' => 6]],
[
'projection' => [
'filename' => 1,
'length' => 1,
'_id' => 0,
],
'sort' => ['length' => -1],
]
);
var_dump($fileDocument);
The output would then resemble::
object(MongoDB\Model\BSONDocument)#3004 (1) {
["storage":"ArrayObject":private]=>
array(2) {
["filename"]=>
string(1) "b"
["length"]=>
int(6)
}
}
See Also See Also
-------- --------
......
...@@ -26,4 +26,17 @@ Return Values ...@@ -26,4 +26,17 @@ Return Values
The name of this bucket as a string. The name of this bucket as a string.
.. todo: add examples Examples
--------
.. code-block:: php
<?php
$bucket = (new MongoDB\Client)->test->selectGridFSBucket();
var_dump($bucket->getBucketName());
The output would then resemble::
string(2) "fs"
...@@ -28,4 +28,17 @@ Return Values ...@@ -28,4 +28,17 @@ Return Values
The chunk size of this bucket in bytes. The chunk size of this bucket in bytes.
.. todo: add examples Examples
--------
.. code-block:: php
<?php
$bucket = (new MongoDB\Client)->test->selectGridFSBucket();
var_dump($bucket->getChunkSizeBytes());
The output would then resemble::
int(261120)
...@@ -28,4 +28,17 @@ Return Values ...@@ -28,4 +28,17 @@ Return Values
A :phpclass:`MongoDB\\Collection` object for the chunks collection. A :phpclass:`MongoDB\\Collection` object for the chunks collection.
.. todo: add examples Examples
--------
.. code-block:: php
<?php
$bucket = (new MongoDB\Client)->test->selectGridFSBucket();
var_dump((string) $bucket->getChunksCollection());
The output would then resemble::
string(14) "test.fs.chunks"
...@@ -26,4 +26,18 @@ Return Values ...@@ -26,4 +26,18 @@ Return Values
The name of the database containing this bucket as a string. The name of the database containing this bucket as a string.
.. todo: add examples Examples
--------
.. code-block:: php
<?php
$bucket = (new MongoDB\Client)->test->selectGridFSBucket();
var_dump($bucket->getDatabaseName());
The output would then resemble::
string(4) "test"
...@@ -37,7 +37,39 @@ Errors/Exceptions ...@@ -37,7 +37,39 @@ Errors/Exceptions
.. include:: /includes/extracts/error-invalidargumentexception.rst .. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst .. include:: /includes/extracts/error-driver-runtimeexception.rst
.. todo: add examples Examples
--------
.. code-block:: php
<?php
$bucket = (new MongoDB\Client)->test->selectGridFSBucket();
$stream = $bucket->openUploadStream('filename');
$fileDocument = $bucket->getFileDocumentForStream($stream);
var_dump($fileDocument);
fclose($stream);
The output would then resemble::
object(MongoDB\Model\BSONDocument)#4956 (1) {
["storage":"ArrayObject":private]=>
array(3) {
["_id"]=>
object(MongoDB\BSON\ObjectId)#4955 (1) {
["oid"]=>
string(24) "5acfb05b7e21e83b5a29037c"
}
["chunkSize"]=>
int(261120)
["filename"]=>
string(8) "filename"
}
}
See Also See Also
-------- --------
......
...@@ -38,7 +38,29 @@ Errors/Exceptions ...@@ -38,7 +38,29 @@ Errors/Exceptions
.. include:: /includes/extracts/error-invalidargumentexception.rst .. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst .. include:: /includes/extracts/error-driver-runtimeexception.rst
.. todo: add examples Examples
--------
.. code-block:: php
<?php
$bucket = (new MongoDB\Client)->test->selectGridFSBucket();
$stream = $bucket->openUploadStream('filename');
$id = $bucket->getFileIdForStream($stream);
var_dump($id);
fclose($stream);
The output would then resemble::
object(MongoDB\BSON\ObjectId)#3005 (1) {
["oid"]=>
string(24) "5acfb37d7e21e83cdb3e1583"
}
See Also See Also
-------- --------
......
...@@ -28,4 +28,20 @@ Return Values ...@@ -28,4 +28,20 @@ Return Values
A :phpclass:`MongoDB\\Collection` object for the files collection. A :phpclass:`MongoDB\\Collection` object for the files collection.
.. todo: add examples Examples
--------
.. code-block:: php
<?php
$bucket = (new MongoDB\Client)->test->selectGridFSBucket();
$filesCollection = $bucket->getFilesCollection();
var_dump($filesCollection->getCollectionName());
The output would then resemble::
string(8) "fs.files"
...@@ -36,7 +36,28 @@ Errors/Exceptions ...@@ -36,7 +36,28 @@ Errors/Exceptions
.. include:: /includes/extracts/error-gridfs-filenotfoundexception.rst .. include:: /includes/extracts/error-gridfs-filenotfoundexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst .. include:: /includes/extracts/error-driver-runtimeexception.rst
.. todo: add examples Examples
--------
.. code-block:: php
<?php
$bucket = (new MongoDB\Client)->test->selectGridFSBucket();
$uploadStream = fopen('php://temp', 'w+b');
fwrite($uploadStream, "foobar");
rewind($uploadStream);
$id = $bucket->uploadFromStream('filename', $uploadStream);
$downloadStream = $bucket->openDownloadStream($id);
var_dump(stream_get_contents($downloadStream));
The output would then resemble::
string(6) "foobar"
See Also See Also
-------- --------
......
...@@ -40,7 +40,26 @@ Errors/Exceptions ...@@ -40,7 +40,26 @@ Errors/Exceptions
.. include:: /includes/extracts/error-gridfs-filenotfoundexception.rst .. include:: /includes/extracts/error-gridfs-filenotfoundexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst .. include:: /includes/extracts/error-driver-runtimeexception.rst
.. todo: add examples Examples
--------
.. code-block:: php
<?php
$bucket = (new MongoDB\Client)->test->selectGridFSBucket();
$stream = fopen('php://temp', 'w+b');
fwrite($stream, "foobar");
rewind($stream);
$bucket->uploadFromStream('filename', $stream);
var_dump(stream_get_contents($bucket->openDownloadStreamByName('filename')));
The output would then resemble::
string(6) "foobar"
See Also See Also
-------- --------
......
...@@ -40,7 +40,25 @@ Behavior ...@@ -40,7 +40,25 @@ Behavior
Chunk documents will be created as data is written to the writable stream. The Chunk documents will be created as data is written to the writable stream. The
metadata document will be created when the writable stream is closed. metadata document will be created when the writable stream is closed.
.. todo: add examples Examples
--------
.. code-block:: php
<?php
$bucket = (new MongoDB\Client)->test->selectGridFSBucket();
$uploadStream = $bucket->openUploadStream('filename');
fwrite($uploadStream, 'foobar');
fclose($uploadStream);
$downloadStream = $bucket->openDownloadStreamByName('filename');
var_dump(stream_get_contents($downloadStream));
The output would then resemble::
string(6) "foobar"
See Also See Also
-------- --------
......
...@@ -31,4 +31,25 @@ Errors/Exceptions ...@@ -31,4 +31,25 @@ Errors/Exceptions
.. include:: /includes/extracts/error-gridfs-filenotfoundexception.rst .. include:: /includes/extracts/error-gridfs-filenotfoundexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst .. include:: /includes/extracts/error-driver-runtimeexception.rst
.. todo: add examples Examples
--------
.. code-block:: php
<?php
$bucket = (new MongoDB\Client)->test->selectGridFSBucket();
$stream = fopen('php://temp', 'w+b');
fwrite($stream, "foobar");
rewind($stream);
$id = $bucket->uploadFromStream('a', $stream);
$bucket->rename($id, 'b');
var_dump(stream_get_contents($bucket->openDownloadStreamByName('b')));
The output would then resemble::
string(6) "foobar"
...@@ -43,7 +43,29 @@ Errors/Exceptions ...@@ -43,7 +43,29 @@ Errors/Exceptions
.. include:: /includes/extracts/error-invalidargumentexception.rst .. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-runtimeexception.rst .. include:: /includes/extracts/error-driver-runtimeexception.rst
.. todo: add examples Examples
--------
.. code-block:: php
<?php
$bucket = (new MongoDB\Client)->test->selectGridFSBucket();
$stream = fopen('php://temp', 'w+b');
fwrite($stream, "foobar");
rewind($stream);
$id = $bucket->uploadFromStream('filename', $stream);
var_dump($id);
The output would then resemble::
object(MongoDB\BSON\ObjectId)#3009 (1) {
["oid"]=>
string(24) "5acf81017e21e816e538d883"
}
See Also See Also
-------- --------
......
...@@ -42,7 +42,25 @@ from the :php:`MongoDB\\Driver\\Manager <class.mongodb-driver-manager>` object. ...@@ -42,7 +42,25 @@ from the :php:`MongoDB\\Driver\\Manager <class.mongodb-driver-manager>` object.
If you select the Bucket from a :phpclass:`Database <MongoDB\\Database>` object, If you select the Bucket from a :phpclass:`Database <MongoDB\\Database>` object,
the Bucket inherits its options from that object. the Bucket inherits its options from that object.
.. todo: add an example Examples
--------
.. code-block:: php
<?php
$bucket = (new MongoDB\Client)->test->selectGridFSBucket();
var_dump($bucket);
The output would then resemble::
object(MongoDB\GridFS\Bucket)#3053 (2) {
["bucketName"]=>
string(4) "test"
["databaseName"]=>
string(11) "phplib_test"
}
See Also See Also
-------- --------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment