Commit fc12c77c authored by Jeremy Mikola's avatar Jeremy Mikola

Add stream debug methods, update docs, and remove unused methods

Classes using CollectionWrapper should rely on its public API rather than work with its files and chunks collections directly.
parent 6b9e7b05
......@@ -17,7 +17,9 @@ use stdClass;
*/
class CollectionWrapper
{
private $bucketName;
private $chunksCollection;
private $databaseName;
private $checkedIndexes = false;
private $filesCollection;
......@@ -33,6 +35,9 @@ class CollectionWrapper
*/
public function __construct(Manager $manager, $databaseName, $bucketName, array $collectionOptions = [])
{
$this->databaseName = (string) $databaseName;
$this->bucketName = (string) $bucketName;
$this->filesCollection = new Collection($manager, $databaseName, sprintf('%s.files', $bucketName), $collectionOptions);
$this->chunksCollection = new Collection($manager, $databaseName, sprintf('%s.chunks', $bucketName), $collectionOptions);
}
......@@ -135,10 +140,14 @@ class CollectionWrapper
return $this->filesCollection->find($filter, $options);
}
// TODO: Remove this
public function getChunksCollection()
/**
* Return the bucket name.
*
* @return string
*/
public function getBucketName()
{
return $this->chunksCollection;
return $this->bucketName;
}
/**
......@@ -160,10 +169,14 @@ class CollectionWrapper
return new IteratorIterator($cursor);
}
// TODO: Remove this
public function getFilesCollection()
/**
* Return the database name.
*
* @return string
*/
public function getDatabaseName()
{
return $this->filesCollection;
return $this->databaseName;
}
/**
......
......@@ -20,6 +20,7 @@ class ReadableStream
private $chunkSize;
private $chunkOffset = 0;
private $chunksIterator;
private $collectionWrapper;
private $firstCheck = true;
private $id;
private $iteratorEmpty = false;
......@@ -52,10 +53,28 @@ class ReadableStream
$this->length = $file->length;
$this->chunksIterator = $collectionWrapper->getChunksIteratorByFilesId($this->id);
$this->collectionWrapper = $collectionWrapper;
$this->numChunks = ceil($this->length / $this->chunkSize);
$this->initEmptyBuffer();
}
/**
* Return internal properties for debugging purposes.
*
* @see http://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.debuginfo
* @return array
*/
public function __debugInfo()
{
return [
'bucketName' => $this->collectionWrapper->getBucketName(),
'databaseName' => $this->collectionWrapper->getDatabaseName(),
'id' => $this->id,
'chunkSize' => $this->chunkSize,
'length' => $this->length,
];
}
public function close()
{
fclose($this->buffer);
......@@ -129,7 +148,7 @@ class ReadableStream
}
/**
* Return the ID of the GridFS file document for this stream.
* Return the stream's ID (i.e. file document identifier).
*
* @return integer
*/
......@@ -139,7 +158,7 @@ class ReadableStream
}
/**
* Return the stream size in bytes.
* Return the stream's size in bytes.
*
* @return integer
*/
......
......@@ -89,6 +89,21 @@ class WritableStream
] + array_intersect_key($options, ['aliases' => 1, 'contentType' => 1, 'metadata' => 1]);
}
/**
* Return internal properties for debugging purposes.
*
* @see http://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.debuginfo
* @return array
*/
public function __debugInfo()
{
return [
'bucketName' => $this->collectionWrapper->getBucketName(),
'databaseName' => $this->collectionWrapper->getDatabaseName(),
'file' => $this->file,
];
}
/**
* Closes an active stream and flushes all buffered data to GridFS.
*/
......@@ -111,26 +126,23 @@ class WritableStream
$this->isClosed = true;
}
public function getChunkSize()
{
return $this->chunkSize;
}
public function getFile()
{
return $this->file;
}
/**
* Return the stream's ID (i.e. file document identifier).
*
* @return integer
*/
public function getId()
{
return $this->file['_id'];
}
public function getLength()
{
return $this->length;
}
/**
* Return the stream's size in bytes.
*
* Note: this value will increase as more data is written to the stream.
*
* @return integer
*/
public function getSize()
{
return $this->length;
......
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