Change record status: 
Project: 
Introduced in branch: 
8.x
Description: 

To assist with custom stream wrapper implementations, two new abstract read-only stream wrapper classes have been added:

\Drupal\Core\StreamWrapper\ReadOnlyStream
An abstract implementation of StreamWrapperInterface which defines the write-related functions, disallowing attempts to write to the stream wrapper.
\Drupal\Core\StreamWrapper\LocalReadOnlyStream
An abstract extension of LocalStream which extends the write-related functions, disallowing attempts to write to the stream wrapper but provides a default implementation to read from local files.

These are intended for extension by other read-only stream wrapper classes, eliminating the need to implement the various write() functions in the extending classes definition.

Attempts to write to a stream wrapper leveraging these classes will generate an E_USER_WARNING in the following situations:

  • any attempt to open the stream wrapper for any mode other than 'r' (i.e. read),
  • any attempt to acquire an exclusive lock (shared locks are still permitted),
  • any attempt to output content (fwrite(), file_put_contents(), etc),
  • any attempt to flush output (e.g. fflush()),
  • any attempt to modify the or delete the file (i.e. chmod(), rename(), or unlink()),
  • any attempt to create or remove a directory (i.e. mkdir(), rmdir()).
Impacts: 
Module developers