function ReadOnlyStream::stream_open
Same name in other branches
- 9 core/lib/Drupal/Core/StreamWrapper/ReadOnlyStream.php \Drupal\Core\StreamWrapper\ReadOnlyStream::stream_open()
- 8.9.x core/lib/Drupal/Core/StreamWrapper/ReadOnlyStream.php \Drupal\Core\StreamWrapper\ReadOnlyStream::stream_open()
- 10 core/lib/Drupal/Core/StreamWrapper/ReadOnlyStream.php \Drupal\Core\StreamWrapper\ReadOnlyStream::stream_open()
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.
int $mode: The file mode, only strict readonly modes are supported.
int $options: A bit mask of STREAM_USE_PATH and STREAM_REPORT_ERRORS.
string $opened_path: A string containing the path actually opened.
Return value
bool TRUE if $mode denotes a readonly mode and the file was opened successfully, FALSE otherwise.
Throws
\BadMethodCallException When ::getLocalPath() is not implemented in the concrete driver class.
Overrides PhpStreamWrapperInterface::stream_open
See also
http://php.net/manual/streamwrapper.stream-open.php
File
-
core/
lib/ Drupal/ Core/ StreamWrapper/ ReadOnlyStream.php, line 76
Class
- ReadOnlyStream
- Defines a read-only Drupal stream wrapper base class.
Namespace
Drupal\Core\StreamWrapperCode
public function stream_open($uri, $mode, $options, &$opened_path) {
if (!in_array($mode, [
'r',
'rb',
'rt',
])) {
if ($options & STREAM_REPORT_ERRORS) {
trigger_error('stream_open() write modes not supported for read-only stream wrappers', E_USER_WARNING);
}
return FALSE;
}
$this->uri = $uri;
$path = $this->getLocalPath();
$this->handle = $options & STREAM_REPORT_ERRORS ? fopen($path, $mode) : @fopen($path, $mode);
if ($this->handle !== FALSE && $options & STREAM_USE_PATH) {
$opened_path = $path;
}
return (bool) $this->handle;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.