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

bool
dir_closedir()

No description

bool
dir_opendir($path, $options)

No description

string
dir_readdir()

No description

bool
dir_rewinddir()

No description

bool
mkdir($path, $mode, $options)

No description

bool
rename($path_from, $path_to)

No description

bool
rmdir($path, $options)

No description

resource|false
stream_cast(int $cast_as)

Retrieve the underlying stream resource.

stream_close()

Closes stream.

bool
stream_eof()

No description

bool
stream_flush()

No description

bool
stream_lock($operation)

No description

bool
stream_metadata(string $path, int $option, mixed $value)

Sets metadata on the stream.

bool
stream_open($path, $mode, $options, $opened_path)

No description

string
stream_read($count)

No description

bool
stream_seek(int $offset, int $whence = SEEK_SET)

Seeks to specific location in a stream.

bool
stream_set_option(int $option, int $arg1, int $arg2)

Change stream options.

array
stream_stat()

No description

int
stream_tell()

No description

bool
stream_truncate(int $new_size)

Truncate stream.

int
stream_write($data)

No description

bool
unlink($path)

No description

array
url_stat($path, $flags)

No description

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.

string
getUri()

Returns the stream resource URI.

string
getExternalUrl()

Returns a web accessible URL for the resource.

string
realpath()

Returns canonical, absolute path of the resource.

string
dirname(string $uri = NULL)

Gets the name of the directory from a given path.

Details

bool dir_closedir()

No description

Return Value

bool

bool dir_opendir($path, $options)

No description

Parameters

$path
$options

Return Value

bool

string dir_readdir()

No description

Return Value

string

bool dir_rewinddir()

No description

Return Value

bool

bool mkdir($path, $mode, $options)

No description

Parameters

$path
$mode
$options

Return Value

bool

bool rename($path_from, $path_to)

No description

Parameters

$path_from
$path_to

Return Value

bool

bool rmdir($path, $options)

No description

Parameters

$path
$options

Return Value

bool

resource|false stream_cast(int $cast_as)

Retrieve the underlying stream resource.

This method is called in response to stream_select().

Parameters

int $cast_as

Can be STREAM_CAST_FOR_SELECT when stream_select() is calling stream_cast() or STREAM_CAST_AS_STREAM when stream_cast() is called for other uses.

Return Value

resource|false

The underlying stream resource or FALSE if stream_select() is not supported.

See also

stream_select()
http://php.net/manual/streamwrapper.stream-cast.php

stream_close()

Closes stream.

bool stream_eof()

No description

Return Value

bool

bool stream_flush()

No description

Return Value

bool

bool stream_lock($operation)

No description

Parameters

$operation

Return Value

bool

bool stream_metadata(string $path, int $option, mixed $value)

Sets metadata on the stream.

Parameters

string $path

A string containing the URI to the file to set metadata on.

int $option

One of:

  • STREAM_META_TOUCH: The method was called in response to touch().
  • STREAM_META_OWNER_NAME: The method was called in response to chown() with string parameter.
  • STREAM_META_OWNER: The method was called in response to chown().
  • STREAM_META_GROUP_NAME: The method was called in response to chgrp().
  • STREAM_META_GROUP: The method was called in response to chgrp().
  • STREAM_META_ACCESS: The method was called in response to chmod().
mixed $value

If option is:

  • STREAM_META_TOUCH: Array consisting of two arguments of the touch() function.
  • STREAM_META_OWNER_NAME or STREAM_META_GROUP_NAME: The name of the owner user/group as string.
  • STREAM_META_OWNER or STREAM_META_GROUP: The value of the owner user/group as integer.
  • STREAM_META_ACCESS: The argument of the chmod() as integer.

Return Value

bool

Returns TRUE on success or FALSE on failure. If $option is not implemented, FALSE should be returned.

See also

http://php.net/manual/streamwrapper.stream-metadata.php

bool stream_open($path, $mode, $options, $opened_path)

No description

Parameters

$path
$mode
$options
$opened_path

Return Value

bool

string stream_read($count)

No description

Parameters

$count

Return Value

string

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.

Parameters

int $offset

The byte offset to seek to.

int $whence

Possible values:

  • SEEK_SET: Set position equal to offset bytes.
  • SEEK_CUR: Set position to current location plus offset.
  • SEEK_END: Set position to end-of-file plus offset. Defaults to SEEK_SET.

Return Value

bool

TRUE if the position was updated, FALSE otherwise.

See also

http://php.net/manual/streamwrapper.stream-seek.php

bool stream_set_option(int $option, int $arg1, int $arg2)

Change stream options.

This method is called to set options on the stream.

Parameters

int $option

One of:

  • STREAM_OPTION_BLOCKING: The method was called in response to stream_set_blocking().
  • STREAM_OPTION_READ_TIMEOUT: The method was called in response to stream_set_timeout().
  • STREAM_OPTION_WRITE_BUFFER: The method was called in response to stream_set_write_buffer().
int $arg1

If option is:

  • STREAM_OPTION_BLOCKING: The requested blocking mode:
    • 1 means blocking.
    • 0 means not blocking.
  • STREAM_OPTION_READ_TIMEOUT: The timeout in seconds.
  • STREAM_OPTION_WRITE_BUFFER: The buffer mode, STREAM_BUFFER_NONE or STREAM_BUFFER_FULL.
int $arg2

If option is:

  • STREAM_OPTION_BLOCKING: This option is not set.
  • STREAM_OPTION_READ_TIMEOUT: The timeout in microseconds.
  • STREAM_OPTION_WRITE_BUFFER: The requested buffer size.

Return Value

bool

TRUE on success, FALSE otherwise. If $option is not implemented, FALSE should be returned.

array stream_stat()

No description

Return Value

array

int stream_tell()

No description

Return Value

int

bool stream_truncate(int $new_size)

Truncate stream.

Will respond to truncation; e.g., through ftruncate().

Parameters

int $new_size

The new size.

Return Value

bool

TRUE on success, FALSE otherwise.

int stream_write($data)

No description

Parameters

$data

Return Value

int

No description

Parameters

$path

Return Value

bool

array url_stat($path, $flags)

No description

Parameters

$path
$flags

Return Value

array

static int getType()

Returns the type of stream wrapper.

Return Value

int

string getName()

Returns the name of the stream wrapper for use in the UI.

Return Value

string

The stream wrapper name.

string getDescription()

Returns the description of the stream wrapper for use in the UI.

Return Value

string

The stream wrapper description.

setUri(string $uri)

Sets the absolute stream resource URI.

This allows you to set the URI. Generally is only called by the factory method.

Parameters

string $uri

A string containing the URI that should be used for this instance.

string getUri()

Returns the stream resource URI.

Return Value

string

Returns the current URI of the instance.

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".

Return Value

string

Returns a string containing a web accessible URL for the resource.

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.

Return Value

string

Returns a string with absolute pathname on success (implemented by core wrappers), or FALSE on failure or if the registered wrapper does not provide an implementation.

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.

Parameters

string $uri

An optional URI.

Return Value

string

A string containing the directory name, or FALSE if not applicable.

See also

FileSystemInterface::dirname