Example stream wrapper class to handle session:// streams.

This is just an example, as it could have horrible results if much information were placed in the $_SESSION variable. However, it does demonstrate both the read and write implementation of a stream wrapper.

A "stream" is an important Unix concept for the reading and writing of files and other devices. Reading or writing a "stream" just means that you open some device, file, internet site, or whatever, and you don't have to know at all what it is. All the functions that deal with it are the same. You can read/write more from/to the stream, seek a position in the stream, or anything else without the code that does it even knowing what kind of device it is talking to. This Unix idea is extended into PHP's mindset.

The idea of "stream wrapper" is that this can be extended indefinitely. The classic example is HTTP: With PHP you can do a file_get_contents("http://DOCUMENTATION_PENDING/projects") as if it were a file, because the scheme "http" is supported natively in PHP. So Backdrop adds the public:// and private:// schemes, and contrib modules can add any scheme they want to. This example adds the session:// scheme, which allows reading and writing the $_SESSION['file_example'] key as if it were a file.

Note that because this implementation uses simple PHP arrays ($_SESSION) it is limited to string values, so binary files will not work correctly. Only text files can be used.


Expanded class hierarchy of FileExampleSessionStreamWrapper

Related topics


modules/examples/file_example/file_example_session_streams.inc, line 40
Provides a demonstration session:// streamwrapper.


Contains filters are case sensitive
Namesort descending Modifiers Type Description
FileExampleSessionStreamWrapper::$context public property Stream context resource.
FileExampleSessionStreamWrapper::$directoryKeys protected property List of keys in a given directory.
FileExampleSessionStreamWrapper::$directoryPointer protected property Pointer to where we are in a directory read.
FileExampleSessionStreamWrapper::$sessionContent protected property The content of the stream.
FileExampleSessionStreamWrapper::$streamPointer protected property The pointer to the next read or write within the session variable.
FileExampleSessionStreamWrapper::$uri protected property Instance URI (stream).
FileExampleSessionStreamWrapper::chmod public function We have no concept of chmod, so just return TRUE. Overrides BackdropStreamWrapperInterface::chmod
FileExampleSessionStreamWrapper::dirname public function Gets the name of the directory from a given path. Overrides BackdropStreamWrapperInterface::dirname
FileExampleSessionStreamWrapper::dir_closedir public function Support for closedir(). Overrides StreamWrapperInterface::dir_closedir
FileExampleSessionStreamWrapper::dir_opendir public function Support for opendir(). Overrides StreamWrapperInterface::dir_opendir
FileExampleSessionStreamWrapper::dir_readdir public function Support for readdir(). Overrides StreamWrapperInterface::dir_readdir
FileExampleSessionStreamWrapper::dir_rewinddir public function Support for rewinddir(). Overrides StreamWrapperInterface::dir_rewinddir
FileExampleSessionStreamWrapper::getDirectoryPath public function Implements getDirectoryPath().
FileExampleSessionStreamWrapper::getExternalUrl public function Overrides getExternalUrl(). Overrides BackdropStreamWrapperInterface::getExternalUrl
FileExampleSessionStreamWrapper::getLocalPath protected function Returns the local path.
FileExampleSessionStreamWrapper::getMimeType public static function Implements getMimeType(). Overrides BackdropStreamWrapperInterface::getMimeType
FileExampleSessionStreamWrapper::getTarget public function Implements getTarget().
FileExampleSessionStreamWrapper::getUri public function Implements getUri(). Overrides BackdropStreamWrapperInterface::getUri
FileExampleSessionStreamWrapper::mkdir public function Support for mkdir(). Overrides StreamWrapperInterface::mkdir
FileExampleSessionStreamWrapper::realpath public function Implements realpath(). Overrides BackdropStreamWrapperInterface::realpath
FileExampleSessionStreamWrapper::rename public function Support for rename(). Overrides StreamWrapperInterface::rename
FileExampleSessionStreamWrapper::rmdir public function Support for rmdir(). Overrides StreamWrapperInterface::rmdir
FileExampleSessionStreamWrapper::setUri public function Implements setUri(). Overrides BackdropStreamWrapperInterface::setUri
FileExampleSessionStreamWrapper::stream_close public function Support for fclose(). Overrides StreamWrapperInterface::stream_close
FileExampleSessionStreamWrapper::stream_eof public function Support for feof(). Overrides StreamWrapperInterface::stream_eof
FileExampleSessionStreamWrapper::stream_flush public function Support for fflush(). Overrides StreamWrapperInterface::stream_flush
FileExampleSessionStreamWrapper::stream_lock public function Support for flock(). Overrides StreamWrapperInterface::stream_lock
FileExampleSessionStreamWrapper::stream_open public function Opens a stream, as for fopen(), file_get_contents(), file_put_contents(). Overrides StreamWrapperInterface::stream_open
FileExampleSessionStreamWrapper::stream_read public function Support for fread(), file_get_contents() etc. Overrides StreamWrapperInterface::stream_read
FileExampleSessionStreamWrapper::stream_seek public function Support for fseek(). Overrides StreamWrapperInterface::stream_seek
FileExampleSessionStreamWrapper::stream_stat public function Support for fstat(). Overrides StreamWrapperInterface::stream_stat
FileExampleSessionStreamWrapper::stream_tell public function Support for ftell(). Overrides StreamWrapperInterface::stream_tell
FileExampleSessionStreamWrapper::stream_write public function Support for fwrite(), file_put_contents() etc. Overrides StreamWrapperInterface::stream_write
FileExampleSessionStreamWrapper::unlink public function Support for unlink(). Overrides StreamWrapperInterface::unlink
FileExampleSessionStreamWrapper::uri_to_session_key protected function Return a reference to the correct $_SESSION key.
FileExampleSessionStreamWrapper::url_stat public function Support for stat(). Overrides StreamWrapperInterface::url_stat
FileExampleSessionStreamWrapper::__construct public function Constructor method.