LocalReadOnlyStream
abstract class LocalReadOnlyStream extends LocalStream (View source)
Defines a read-only Drupal stream wrapper base class for local files.
This class extends the complete stream wrapper implementation in LocalStream. 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\LocalReadOnlyStream implementations need to implement at least the getDirectoryPath() and getExternalUrl() methods.
Properties
| resource | $context | Stream context resource. |
from LocalStream |
| resource | $handle | A generic resource handle. |
from LocalStream |
| protected string | $uri | Instance URI (stream). |
from LocalStream |
Methods
Returns the type of stream wrapper.
Returns the local writable target of the resource within the stream.
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 fwrite(), file_put_contents() etc.
Seeks to specific location in a stream.
Support for fflush().
Sets metadata on the stream.
Truncate stream.
Support for unlink().
Support for rename().
Gets the name of the directory from a given path.
Support for mkdir().
Support for rmdir().
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().
An exclusive lock attempt will be rejected, as this is a read-only stream wrapper.
string
stream_read($count)
Support for fread(), file_get_contents() etc.
int
stream_write($data)
Support for fwrite(), file_put_contents() etc.
Data will not be written as this is a read-only stream wrapper.
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().
Nothing will be output to the file, as this is a read-only stream wrapper. However as stream_flush is called during stream_close we should not trigger an error.
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().
The file will not be deleted from the stream as this is a read-only stream wrapper.
bool
rename(string $from_uri, string $to_uri)
Support for rename().
The file will not be renamed as this is a read-only stream wrapper.
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().
Directory will never be created as this is a read-only stream wrapper.
bool
rmdir(string $uri, $options)
Support for rmdir().
Directory will never be deleted as this is a read-only stream wrapper.
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().