Class yii\mongodb\file\StreamWrapper
Inheritance | yii\mongodb\file\StreamWrapper » yii\base\BaseObject |
---|---|
Implements | yii\base\Configurable |
Available since version | 2.1 |
Source Code | https://github.com/yiisoft/yii2-mongodb/blob/master/file/StreamWrapper.php |
StreamWrapper provides stream wrapper for MongoDB GridFS, allowing file operations via regular PHP stream resources.
Before feature can be used this wrapper should be registered via register() method. It is usually performed via yii\mongodb\Connection::registerFileStreamWrapper().
Note: do not use this class directly - its instance will be created and maintained by PHP internally once corresponding stream resource is created.
Resource path should be specified in following format:
'protocol://databaseName.fileCollectionPrefix?file_attribute=value'
Write example:
$resource = fopen('gridfs://mydatabase.fs?filename=new_file.txt', 'w');
fwrite($resource, 'some content');
// ...
fclose($resource);
Read example:
$resource = fopen('gridfs://mydatabase.fs?filename=my_file.txt', 'r');
$fileContent = stream_get_contents($resource);
See also http://php.net/manual/en/function.stream-wrapper-register.php.
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$context | resource | Associated stream resource context. | yii\mongodb\file\StreamWrapper |
$contextOptions | array | Context options. | yii\mongodb\file\StreamWrapper |
Public Methods
Method | Description | Defined By |
---|---|---|
__call() | Calls the named method which is not a class method. | yii\base\BaseObject |
__construct() | Constructor. | yii\base\BaseObject |
__get() | Returns the value of an object property. | yii\base\BaseObject |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\base\BaseObject |
__set() | Sets value of an object property. | yii\base\BaseObject |
__unset() | Sets an object property to null. | yii\base\BaseObject |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\base\BaseObject |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\base\BaseObject |
className() | Returns the fully qualified name of this class. | yii\base\BaseObject |
getContextOptions() | Returns options associated with $context. | yii\mongodb\file\StreamWrapper |
hasMethod() | Returns a value indicating whether a method is defined. | yii\base\BaseObject |
hasProperty() | Returns a value indicating whether a property is defined. | yii\base\BaseObject |
init() | Initializes the object. | yii\base\BaseObject |
register() | Registers this steam wrapper. | yii\mongodb\file\StreamWrapper |
stream_close() | Closes a resource. | yii\mongodb\file\StreamWrapper |
stream_eof() | Tests for end-of-file on a file pointer. | yii\mongodb\file\StreamWrapper |
stream_flush() | This method is called in response to fflush() and when the stream is being closed
while any unflushed data has been written to it before. |
yii\mongodb\file\StreamWrapper |
stream_open() | Opens file. | yii\mongodb\file\StreamWrapper |
stream_read() | Reads from stream. | yii\mongodb\file\StreamWrapper |
stream_seek() | Seeks to specific location in a stream. | yii\mongodb\file\StreamWrapper |
stream_stat() | Retrieve information about a file resource. | yii\mongodb\file\StreamWrapper |
stream_tell() | Retrieve the current position of a stream. | yii\mongodb\file\StreamWrapper |
stream_write() | Writes to stream. | yii\mongodb\file\StreamWrapper |
Property Details
Associated stream resource context. This property is set automatically by PHP once wrapper is instantiated.
Context options.
Method Details
Returns options associated with $context.
public array getContextOptions ( ) | ||
return | array | Context options. |
---|
Registers this steam wrapper.
public static void register ( $protocol = 'gridfs', $force = false ) | ||
$protocol | string | Name of the protocol to be used. |
$force | boolean | Whether to register wrapper, even if protocol is already taken. |
Closes a resource.
This method is called in response to fclose()
.
See also fclose().
public void stream_close ( ) |
Tests for end-of-file on a file pointer.
This method is called in response to feof()
.
See also feof().
public boolean stream_eof ( ) | ||
return | boolean |
|
---|
This method is called in response to fflush()
and when the stream is being closed
while any unflushed data has been written to it before.
See also fflush().
public boolean stream_flush ( ) | ||
return | boolean | Whether cached data was successfully stored. |
---|
Opens file.
This method is called immediately after the wrapper is initialized (f.e. by fopen()
and file_get_contents()
).
See also fopen().
public boolean stream_open ( $path, $mode, $options, &$openedPath ) | ||
$path | string | Specifies the URL that was passed to the original function. |
$mode | string | Mode used to open the file, as detailed for |
$options | integer | Additional flags set by the streams API. |
$openedPath | string | Real opened path. |
return | boolean | Whether operation is successful. |
---|
Reads from stream.
This method is called in response to fread()
and fgets()
.
See also fread().
public string|false stream_read ( $count ) | ||
$count | integer | Count of bytes of data from the current position should be returned. |
return | string|false | If there are less than count bytes available, return as many as are available.
If no more data is available, return |
---|
Seeks to specific location in a stream.
This method is called in response to fseek()
.
See also fseek().
public boolean stream_seek ( $offset, $whence = SEEK_SET ) | ||
$offset | integer | The stream offset to seek to. |
$whence | integer | Possible values:
|
return | boolean | Return true if the position was updated, false otherwise. |
---|
Retrieve information about a file resource.
This method is called in response to stat()
.
See also stat().
public array stream_stat ( ) | ||
return | array | File statistic information. |
---|
Retrieve the current position of a stream.
This method is called in response to fseek()
to determine the current position.
See also fseek().
public integer stream_tell ( ) | ||
return | integer | Should return the current position of the stream. |
---|
Writes to stream.
This method is called in response to fwrite()
.
See also fwrite().
public integer stream_write ( $data ) | ||
$data | string | String to be stored into the underlying stream. |
return | integer | The number of bytes that were successfully stored. |
---|