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, $mode, $options, $opened_path)

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

bool
stream_lock($operation)

Support for flock().

int
stream_write($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, $mode, $options)

Support for mkdir().

bool
rmdir(string $uri, $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, $mode, $options, $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.

$mode
$options
$opened_path

Return Value

bool

See also

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

bool stream_lock($operation)

Support for flock().

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

Parameters

$operation

Return Value

bool

See also

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

int stream_write($data)

Support for fwrite(), file_put_contents() etc.

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

Parameters

$data

Return Value

int

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.

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

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

See also

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

bool mkdir(string $uri, $mode, $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.

$mode
$options

Return Value

bool

See also

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

bool rmdir(string $uri, $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.

$options

Return Value

bool

See also

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