LocalStream
abstract class LocalStream implements StreamWrapperInterface (View source)
Defines a Drupal stream wrapper base class for local files.
This class provides a complete stream wrapper implementation. URIs such as "public://example.txt" are expanded to a normal filesystem path such as "sites/default/files/example.txt" and then PHP filesystem functions are invoked.
Drupal\Core\StreamWrapper\LocalStream implementations need to implement at least the getDirectoryPath() and getExternalUrl() methods.
Properties
| resource | $context | Stream context resource. |
|
| resource | $handle | A generic resource handle. |
|
| protected string | $uri | Instance URI (stream). |
Methods
Returns the type of stream wrapper.
Gets the path that the wrapper is responsible for.
Sets the absolute stream resource URI.
Returns the stream resource URI.
Returns the local writable target of the resource within the stream.
Returns canonical, absolute path of the resource.
Returns the canonical absolute path of the URI, if possible.
Support for fopen(), file_get_contents(), file_put_contents() etc.
Support for flock().
Support for fread(), file_get_contents() etc.
Support for fwrite(), file_put_contents() etc.
Support for feof().
Seeks to specific location in a stream.
Support for fflush().
Support for ftell().
Support for fstat().
Support for fclose().
Retrieve the underlying stream resource.
Sets metadata on the stream.
Change stream options.
Truncate stream.
Support for unlink().
Support for rename().
Gets the name of the directory from a given path.
Support for mkdir().
Support for rmdir().
Support for stat().
Support for opendir().
Support for readdir().
Support for rewinddir().
Support for closedir().
Details
static int
getType()
Returns the type of stream wrapper.
abstract string
getDirectoryPath()
Gets the path that the wrapper is responsible for.
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.
protected string|bool
getTarget(string $uri = NULL)
Returns the local writable target of the resource within the stream.
This function should be used in place of calls to realpath() or similar functions when attempting to determine the location of a file. While functions like realpath() may return the location of a read-only file, this method may return a URI or path suitable for writing that is completely separate from the URI used for reading.
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.
protected string|bool
getLocalPath(string $uri = NULL)
Returns the canonical absolute path of the URI, if possible.
bool
stream_open(string $uri, $mode, $options, $opened_path)
Support for fopen(), file_get_contents(), file_put_contents() etc.
bool
stream_lock($operation)
Support for flock().
string
stream_read($count)
Support for fread(), file_get_contents() etc.
int
stream_write($data)
Support for fwrite(), file_put_contents() etc.
bool
stream_eof()
Support for feof().
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_flush()
Support for fflush().
int
stream_tell()
Support for ftell().
array
stream_stat()
Support for fstat().
stream_close()
Support for fclose().
resource|false
stream_cast(int $cast_as)
Retrieve the underlying stream resource.
This method is called in response to stream_select().
bool
stream_metadata($uri, int $option, mixed $value)
Sets metadata on the stream.
bool
stream_set_option(int $option, int $arg1, int $arg2)
Change stream options.
This method is called to set options on the stream.
bool
stream_truncate(int $new_size)
Truncate stream.
Will respond to truncation; e.g., through ftruncate().
bool
unlink(string $uri)
Support for unlink().
bool
rename(string $from_uri, string $to_uri)
Support for rename().
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 PHP dirname() function because it does not support stream wrappers.
bool
mkdir(string $uri, $mode, $options)
Support for mkdir().
bool
rmdir(string $uri, $options)
Support for rmdir().
array
url_stat(string $uri, $flags)
Support for stat().
bool
dir_opendir(string $uri, $options)
Support for opendir().
string
dir_readdir()
Support for readdir().
bool
dir_rewinddir()
Support for rewinddir().
bool
dir_closedir()
Support for closedir().