PublicStream
class PublicStream extends LocalStream (View source)
Defines a Drupal public (public://) stream wrapper class.
Provides support for storing publicly accessible files with the Drupal file interface.
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.
Gets the path that the wrapper is responsible for.
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.
Seeks to specific location in a stream.
Gets the name of the directory from a given path.
Returns the name of the stream wrapper for use in the UI.
Returns the description of the stream wrapper for use in the UI.
Returns a web accessible URL for the resource.
Finds and returns the base URL for public://.
Returns the base path for public://.
Details
static int
getType()
Returns the type of stream wrapper.
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().
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.
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".
static string
baseUrl()
Finds and returns the base URL for public://.
Defaults to the current site's base URL plus directory path.
Note that this static method is used by \Drupal\system\Form\FileSystemForm so you should alter that form or substitute a different form if you change the class providing the stream_wrapper.public service.
static string
basePath(string $site_path = NULL)
Returns the base path for public://.
If we have a setting for the public:// scheme's path, we use that. Otherwise we build a reasonable default based on the site.path service if it's available, or a default behavior based on the request.
Note that this static method is used by \Drupal\system\Form\FileSystemForm so you should alter that form or substitute a different form if you change the class providing the stream_wrapper.public service.
The site path is injectable from the site.path service: