StreamWrapperInterface
interface StreamWrapperInterface implements PhpStreamWrapperInterface (View source)
Defines a Drupal stream wrapper extension.
Provides a Drupal interface and classes to implement PHP stream wrappers for public, private, and temporary files. Extends the PhpStreamWrapperInterface with methods expected by Drupal stream wrapper classes.
A stream wrapper is an abstraction of a file system that allows Drupal to use the same set of methods to access both local files and remote resources.
Note that PHP 5.2 fopen() only supports URIs of the form "scheme://target" despite the fact that according to RFC 3986 a URI's scheme component delimiter is in general just ":", not "://". Because of this PHP limitation and for consistency Drupal will only accept URIs of form "scheme://target".
Constants
| ALL |
A filter that matches all wrappers. |
| LOCAL |
Refers to a local file system location. |
| READ |
Wrapper is readable (almost always true). |
| WRITE |
Wrapper is writable. |
| VISIBLE |
Exposed in the UI and potentially web accessible. |
| HIDDEN |
Defines the stream wrapper bit flag for a hidden file. This is not visible in the UI or accessible via web, but readable and writable; for instance, the temporary directory for file uploads. |
| LOCAL_HIDDEN |
Hidden, readable and writable using local files. |
| WRITE_VISIBLE |
Visible, readable and writable. |
| READ_VISIBLE |
Visible and read-only. |
| NORMAL |
This is the default 'type' flag. This does not include
StreamWrapperInterface::LOCAL, because PHP grants a greater trust level to
local files (for example, they can be used in an "include" statement,
regardless of the "allow_url_include" setting), so stream wrappers need to
explicitly opt-in to this. |
| LOCAL_NORMAL |
Visible, readable and writable using local files. |
Methods
Create a directory.
Renames a file or directory.
Retrieve the underlying stream resource.
Sets metadata on the stream.
Opens file or URL.
Seeks to specific location in a stream.
Change stream options.
Retrieve information about a file resource.
Retrieve information about a file.
Returns the type of stream wrapper.
Returns the name of the stream wrapper for use in the UI.
Returns the description of the stream wrapper for use in the UI.
Sets the absolute stream resource URI.
Returns the stream resource URI.
Returns a web accessible URL for the resource.
Returns canonical, absolute path of the resource.
Gets the name of the directory from a given path.
Details
bool
dir_closedir()
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
dir_opendir(string $path, int $options)
Open directory handle.
This method is called in response to opendir().
string|false
dir_readdir()
Read entry from directory handle.
This method is called in response to readdir().
bool
dir_rewinddir()
Rewind directory handle.
This method is called in response to rewinddir(). Should reset the output generated by PhpStreamWrapperInterface::dir_readdir. The next call to PhpStreamWrapperInterface::dir_readdir should return the first entry in the location returned by PhpStreamWrapperInterface::dir_opendir.
bool
mkdir(string $path, int $mode, int $options)
Create a directory.
This method is called in response to mkdir()
Note, in order for the appropriate error message to be returned this method should not be defined if the wrapper does not support creating directories.
Note, the streamWrapper::$context property is updated if a valid context is passed to the caller function.
bool
rename(string $path_from, string $path_to)
Renames a file or directory.
This method is called in response to rename(). Should attempt to rename $path_from to $path_to.
Note, in order for the appropriate error message to be returned this method should not be defined if the wrapper does not support renaming files.
Note, the streamWrapper::$context property is updated if a valid context is passed to the caller function.
bool
rmdir(string $path, int $options)
Removes a directory.
This method is called in response to rmdir().
Note, in order for the appropriate error message to be returned this method should not be defined if the wrapper does not support removing directories.
Note, the streamWrapper::$context property is updated if a valid context is passed to the caller function.
resource|false
stream_cast(int $cast_as)
Retrieve the underlying stream resource.
This method is called in response to stream_select().
stream_close()
Closes stream.
This method is called in response to fclose(). All resources that were locked, or allocated, by the wrapper should be released.
bool
stream_eof()
Tests for end-of-file on a file pointer.
This method is called in response to feof().
Warning, when reading the whole file (for example, with file_get_contents()), PHP will call PhpStreamWrapperInterface::stream_read() followed by PhpStreamWrapperInterface::stream_eof() in a loop but as long as PhpStreamWrapperInterface::stream_read() returns a non-empty string, the return value of PhpStreamWrapperInterface::stream_eof() is ignored.
bool
stream_flush()
Flushes the output.
This method is called in response to fflush() and when the stream is being closed while any un-flushed data has been written to it before. 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
stream_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() and when closing the stream (LOCK_UN).
bool
stream_metadata(string $path, int $option, mixed $value)
Sets metadata on the stream.
bool
stream_open(string $path, string $mode, int $options, string $opened_path)
Opens file or URL.
This method is called immediately after the wrapper is initialized (e.g. by fopen() and file_get_contents()).
Note the streamWrapper::$context property is updated if a valid context is passed to the caller function.
string|false
stream_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).
Note, PhpStreamWrapperInterface::stream_eof() is called directly after calling PhpStreamWrapperInterface::stream_read() to check if EOF has been reached. If not implemented, EOF is assumed.
Warning, when reading the whole file (e.g., with file_get_contents()), PHP will call PhpStreamWrapperInterface::stream_read() followed by PhpStreamWrapperInterface::stream_eof() in a loop but as long as PhpStreamWrapperInterface::stream_read() returns a non-empty string, the return value of PhpStreamWrapperInterface::stream_eof() is ignored.
bool
stream_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.
bool
stream_set_option(int $option, int $arg1, int $arg2)
Change stream options.
This method is called to set options on the stream.
array|false
stream_stat()
Retrieve information about a file resource.
This method is called in response to fstat().
int
stream_tell()
Retrieve the current position of a stream.
This method is called in response to fseek() to determine the current position.
bool
stream_truncate(int $new_size)
Truncate stream.
Will respond to truncation; e.g., through ftruncate().
int
stream_write(string $data)
Write to stream.
This method is called in response to fwrite(). 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.
Note, the streamWrapper::$context property is updated if a valid context is passed to the caller function.
array|false
url_stat(string $path, int $flags)
Retrieve information about a file.
This method is called in response to all stat() related functions.
Note, the streamWrapper::$context property is updated if a valid context is passed to the caller function.
static int
getType()
Returns the type of stream wrapper.
string
getName()
Returns the name of the stream wrapper for use in the UI.
string
getDescription()
Returns the description of the stream wrapper for use in the UI.
setUri(string $uri)
Sets the absolute stream resource URI.
This allows you to set the URI. Generally is only called by the factory method.
string
getUri()
Returns the stream resource URI.
string
getExternalUrl()
Returns a web accessible URL for the resource.
This function should return a URL that can be embedded in a web page and accessed from a browser. For example, the external URL of "youtube://xIpLd0WQKCY" might be "http://www.youtube.com/watch?v=xIpLd0WQKCY".
string
realpath()
Returns canonical, absolute path of the resource.
Implementation placeholder. PHP's realpath() does not support stream wrappers. We provide this as a default so that individual wrappers may implement their own solutions.
string
dirname(string $uri = NULL)
Gets the name of the directory from a given path.
This method is usually accessed through \Drupal\Core\File\FileSystemInterface::dirname(), which wraps around the normal PHP dirname() function, which does not support stream wrappers.