abstract class ReadOnlyStream implements StreamWrapperInterface (View source)

Defines a read-only Drupal stream wrapper base class.

This class provides a minimal-read only stream wrapper implementation. Specifically, it only implements the writing classes and read classes where we need to restrict 'write-capable' arguments.

Drupal\Core\StreamWrapper\ReadOnlyStream implementations need to implement all the read-related classes.

Properties

resource $context

Stream context resource.

resource $handle

A generic resource handle.

protected string $uri

Instance URI (stream).

Methods

setUri(string $uri)

Sets the absolute stream resource URI.

string
getUri()

Returns the stream resource URI.

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

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

bool
stream_lock(int $operation)

Support for flock().

int
stream_write(string $data)

Support for fwrite(), file_put_contents() etc.

bool
stream_flush()

Support for fflush().

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

Sets metadata on the stream.

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().

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

Support for mkdir().

bool
rmdir(string $uri, int $options)

Support for rmdir().

Details

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.

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

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

Any write modes will be rejected, as this is a read-only stream wrapper.

Parameters

string $uri

A string containing the URI to the file to open.

string $mode

The mode used to open the file, as detailed for fopen(). Note, remember to check if the mode is valid for the path requested.

int $options

Holds additional flags set by the streams API. It can hold one or more of the following values ORed together:

  • STREAM_USE_PATH: If path is relative, search for the resource using the include_path.
  • STREAM_REPORT_ERRORS: If this flag is set, you are responsible for raising errors using trigger_error() during opening of the stream. If this flag is not set, you should not raise any errors.
string $opened_path

If the path is opened successfully, and STREAM_USE_PATH is set in options, opened_path should be set to the full path of the file/resource that was actually opened.

Return Value

bool

Returns TRUE on success or FALSE on failure.

See also

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

bool stream_lock(int $operation)

Support for flock().

An exclusive lock attempt will be rejected, as this is a read-only stream wrapper.

Parameters

int $operation

One of:

  • LOCK_SH: To acquire a shared lock (reader).
  • LOCK_EX: To acquire an exclusive lock (writer).
  • LOCK_UN: To release a lock (shared or exclusive).
  • LOCK_NB: If you don't want flock() to block while locking. This operation is not supported on Windows.

Return Value

bool

Returns TRUE on success or FALSE on failure.

See also

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

int stream_write(string $data)

Support for fwrite(), file_put_contents() etc.

Data will not be written as this is a read-only stream wrapper.

Parameters

string $data

Should be stored into the underlying stream. If there is not enough room in the underlying stream, store as much as possible.

Return Value

int

Should return the number of bytes that were successfully stored, or 0 if none could be stored.

See also

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

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.

Return Value

bool

Should return TRUE if the cached data was successfully stored (or if there was no data to store), or FALSE if the data could not be stored.

See also

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

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_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().

The file will not be deleted from the stream as this is a read-only stream wrapper.

Parameters

string $uri

A string containing the uri to the resource to delete.

Return Value

bool

Returns TRUE on success or FALSE on failure.

See also

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

bool rename(string $from_uri, string $to_uri)

Support for rename().

This file will not be renamed as this is a read-only stream wrapper.

Parameters

string $from_uri

The uri to the file to rename.

string $to_uri

The new uri for file.

Return Value

bool

Returns TRUE on success or FALSE on failure.

See also

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

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

Support for mkdir().

Directory will never be created as this is a read-only stream wrapper.

Parameters

string $uri

A string containing the URI to the directory to create.

int $mode

The value passed to mkdir().

int $options

A bitwise mask of values, such as STREAM_MKDIR_RECURSIVE.

Return Value

bool

Returns TRUE on success or FALSE on failure.

See also

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

bool rmdir(string $uri, int $options)

Support for rmdir().

Directory will never be deleted as this is a read-only stream wrapper.

Parameters

string $uri

A string containing the URI to the directory to delete.

int $options

A bitwise mask of values, such as STREAM_MKDIR_RECURSIVE.

Return Value

bool

Returns TRUE on success or FALSE on failure.

See also

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