StreamWrapperInterface
interface StreamWrapperInterface (View source)
A stream wrapper interface. Modeled after the PHP streamWrapper class prototype. Check http://php.net/streamwrapper for details on that.
We divert from the PHP prototype in the following:
- better method names
- methods that should not be implemented in the PHP prototype when not being supported (like mkdir) must throw a \BadMethodCallException instead.
Methods
Returns the scheme ("protocol") this wrapper handles.
Close directory handle.
Open directory handle.
Read entry from directory handle.
Rewind directory handle.
Create a directory.
Removes a directory.
Renames a file or directory.
Retrieve the underlying resource.
Close an resource.
Tests for end-of-file on a file pointer.
Flushes the output.
Advisory file locking.
Advisory file locking.
Opens file or URL.
Read from stream.
Seeks to specific location in a stream.
Change stream options.
Retrieve the current position of a stream.
Write to stream.
Delete a file.
Retrieve information about a file resource.
Retrieve information about a file.
Details
static string
getScheme()
Returns the scheme ("protocol") this wrapper handles.
bool
closeDirectory()
Close directory handle.
This method is called in response to closedir().
Any resources which were locked, or allocated, during opening and use of the directory stream should be released.
bool
openDirectory(string $path, int $options)
Open directory handle.
This method is called in response to opendir().
string
readDirectory()
Read entry from directory handle.
This method is called in response to readdir().
bool
rewindDirectory()
Rewind directory handle.
This method is called in response to rewinddir().
Should reset the output generated by dir_readdir(). I.e.: The next call to dir_readdir() should return the first entry in the location returned by dir_opendir().
bool
makeDirectory(string $path, int $mode, int $options)
Create a directory.
This method is called in response to mkdir().
Note: If the wrapper does not support creating directories it must throw a \BadMethodCallException.
bool
removeDirectory(string $path, int $options)
Removes a directory.
This method is called in response to rmdir().
Note: If the wrapper does not support creating directories it must throw a \BadMethodCallException.
bool
rename(string $source, string $target)
Renames a file or directory.
This method is called in response to rename().
Should attempt to rename path_from to path_to.
resource|false
cast(int $castType)
Retrieve the underlying resource.
This method is called in response to stream_select().
void
close()
Close an resource.
This method is called in response to fclose().
All resources that were locked, or allocated, by the wrapper should be released.
bool
isAtEof()
Tests for end-of-file on a file pointer.
This method is called in response to feof().
bool
flush()
Flushes the output.
This method is called in response to fflush().
If you have cached data in your stream but not yet stored it into the underlying storage, you should do so now.
Note: If not implemented, false is assumed as the return value.
bool
lock(int $operation)
Advisory file locking.
This method is called in response to flock(), when file_put_contents() (when flags contains LOCK_EX), stream_set_blocking().
$operation is one of the following: LOCK_SH to acquire a shared lock (reader). LOCK_EX to acquire an exclusive lock (writer). LOCK_NB if you don't want flock() to block while locking.
bool
unlock()
Advisory file locking.
This method is called when closing the stream (LOCK_UN).
bool
open(string $path, string $mode, int $options, string $openedPathAndFilename)
Opens file or URL.
This method is called immediately after the wrapper is initialized (f.e. by fopen() and file_get_contents()).
$options can hold one of the following values OR'd together: STREAM_USE_PATH If path is relative, search for the resource using the include_path. STREAM_REPORT_ERRORS If this flag is set, you are responsible for raising errors using trigger_error() during opening of the stream. If this flag is not set, you should not raise any errors.
string
read(int $count)
Read from stream.
This method is called in response to fread() and fgets().
Note: Remember to update the read/write position of the stream (by the number of bytes that were successfully read).
bool
seek(int $offset, int $whence = SEEK_SET)
Seeks to specific location in a stream.
This method is called in response to fseek().
The read/write position of the stream should be updated according to the offset and whence .
$whence can one of: SEEK_SET - Set position equal to offset bytes. SEEK_CUR - Set position to current location plus offset. SEEK_END - Set position to end-of-file plus offset.
bool
setOption(int $option, int $argument1, int $argument2)
Change stream options.
This method is called to set options on the stream.
$option can be one of: STREAM_OPTION_BLOCKING (The method was called in response to stream_set_blocking()) STREAM_OPTION_READ_TIMEOUT (The method was called in response to stream_set_timeout()) STREAM_OPTION_WRITE_BUFFER (The method was called in response to stream_set_write_buffer())
If $option is ... then $arg1 is set to: STREAM_OPTION_BLOCKING: requested blocking mode (1 meaning block 0 not blocking). STREAM_OPTION_READ_TIMEOUT: the timeout in seconds. STREAM_OPTION_WRITE_BUFFER: buffer mode (STREAM_BUFFER_NONE or STREAM_BUFFER_FULL).
If $option is ... then $arg2 is set to: STREAM_OPTION_BLOCKING: This option is not set. STREAM_OPTION_READ_TIMEOUT: the timeout in microseconds. STREAM_OPTION_WRITE_BUFFER: the requested buffer size.
int
tell()
Retrieve the current position of a stream.
This method is called in response to ftell().
int
write(string $data)
Write to stream.
This method is called in response to fwrite().
If there is not enough room in the underlying stream, store as much as possible.
Note: Remember to update the current position of the stream by number of bytes that were successfully written.
bool
unlink(string $path)
Delete a file.
This method is called in response to unlink().
Note: In order for the appropriate error message to be returned this method should not be defined if the wrapper does not support removing files.
array
resourceStat()
Retrieve information about a file resource.
This method is called in response to fstat().
array
pathStat(string $path, int $flags)
Retrieve information about a file.
This method is called in response to all stat() related functions.
$flags can hold one or more of the following values OR'd together: STREAM_URL_STAT_LINK For resources with the ability to link to other resource (such as an HTTP Location: forward, or a filesystem symlink). This flag specified that only information about the link itself should be returned, not the resource pointed to by the link. This flag is set in response to calls to lstat(), is_link(), or filetype(). STREAM_URL_STAT_QUIET If this flag is set, your wrapper should not raise any errors. If this flag is not set, you are responsible for reporting errors using the trigger_error() function during stating of the path.