class TemporaryStream extends LocalStream (View source)

Defines a Drupal temporary (temporary://) stream wrapper class.

Provides support for storing temporarily 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

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.

string
getUri()

Returns the stream resource URI.

string|bool
getTarget(string $uri = NULL)

Returns the local writable target of the resource within the stream.

string
realpath()

Returns canonical, absolute path of the resource.

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.

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.

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.

bool
stream_truncate(int $new_size)

Truncate stream.

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.

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.

Details

static int getType()

Returns the type of stream wrapper.

Return Value

int

string getDirectoryPath()

Gets the path that the wrapper is responsible for.

Return Value

string

String specifying the path.

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.

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.

Parameters

string $uri

Optional URI.

Return Value

string|bool

Returns a string representing a location suitable for writing of a file, or FALSE if unable to write to the file such as with read-only streams.

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.

protected string|bool getLocalPath(string $uri = NULL)

Returns the canonical absolute path of the URI, if possible.

Parameters

string $uri

(optional) The stream wrapper URI to be converted to a canonical absolute path. This may point to a directory or another type of file.

Return Value

string|bool

If $uri is not set, returns the canonical absolute path of the URI previously set by the Drupal\Core\StreamWrapper\StreamWrapperInterface::setUri() function. If $uri is set and valid for this class, returns its canonical absolute path, as determined by the realpath() function. If $uri is set but not valid, returns FALSE.

bool stream_open(string $uri, $mode, $options, $opened_path)

Support for fopen(), file_get_contents(), file_put_contents() etc.

Parameters

string $uri

A string containing the URI to the file to open.

$mode
$options
$opened_path

Return Value

bool

See also

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

bool stream_lock($operation)

Support for flock().

Parameters

$operation

Return Value

bool

See also

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

string stream_read($count)

Support for fread(), file_get_contents() etc.

Parameters

$count

Return Value

string

See also

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

int stream_write($data)

Support for fwrite(), file_put_contents() etc.

Parameters

$data

Return Value

int

See also

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

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.

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.

bool stream_flush()

Support for fflush().

int stream_tell()

Support for ftell().

array stream_stat()

Support for fstat().

stream_close()

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.

bool stream_metadata($uri, int $option, mixed $value)

Sets metadata on the stream.

Parameters

$uri
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.

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.

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.

Support for unlink().

Parameters

string $uri

A string containing the URI to the resource to delete.

Return Value

bool

See also

http://php.net/manual/streamwrapper.unlink.php

bool rename(string $from_uri, string $to_uri)

Support for rename().

Parameters

string $from_uri

The URI to the file to rename.

string $to_uri

The new URI for file.

Return Value

bool

See also

http://php.net/manual/streamwrapper.rename.php

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.

Parameters

string $uri

An optional URI.

Return Value

string

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

See also

FileSystemInterface::dirname

bool mkdir(string $uri, $mode, $options)

Support for mkdir().

Parameters

string $uri

A string containing the URI to the directory to create.

$mode
$options

Return Value

bool

See also

http://php.net/manual/streamwrapper.mkdir.php

bool rmdir(string $uri, $options)

Support for rmdir().

Parameters

string $uri

A string containing the URI to the directory to delete.

$options

Return Value

bool

See also

http://php.net/manual/streamwrapper.rmdir.php

array url_stat(string $uri, $flags)

Support for stat().

Parameters

string $uri

A string containing the URI to get information about.

$flags

Return Value

array

See also

http://php.net/manual/streamwrapper.url-stat.php

bool dir_opendir(string $uri, $options)

Support for opendir().

Parameters

string $uri

A string containing the URI to the directory to open.

$options

Return Value

bool

See also

http://php.net/manual/streamwrapper.dir-opendir.php

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.

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.

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.