Chris@0: uri = $uri; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getUri() { Chris@0: return $this->uri; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Support for fopen(), file_get_contents(), etc. Chris@0: * Chris@0: * Any write modes will be rejected, as this is a read-only stream wrapper. Chris@0: * Chris@0: * @param string $uri Chris@0: * A string containing the URI to the file to open. Chris@0: * @param int $mode Chris@0: * The file mode, only strict readonly modes are supported. Chris@0: * @param int $options Chris@0: * A bit mask of STREAM_USE_PATH and STREAM_REPORT_ERRORS. Chris@0: * @param string $opened_path Chris@0: * A string containing the path actually opened. Chris@0: * Chris@0: * @return bool Chris@0: * TRUE if $mode denotes a readonly mode and the file was opened Chris@0: * successfully, FALSE otherwise. Chris@0: * Chris@0: * @see http://php.net/manual/streamwrapper.stream-open.php Chris@0: */ Chris@0: public function stream_open($uri, $mode, $options, &$opened_path) { Chris@0: if (!in_array($mode, ['r', 'rb', 'rt'])) { Chris@0: if ($options & STREAM_REPORT_ERRORS) { Chris@0: trigger_error('stream_open() write modes not supported for read-only stream wrappers', E_USER_WARNING); Chris@0: } Chris@0: return FALSE; Chris@0: } Chris@0: Chris@0: $this->uri = $uri; Chris@0: $path = $this->getLocalPath(); Chris@0: $this->handle = ($options & STREAM_REPORT_ERRORS) ? fopen($path, $mode) : @fopen($path, $mode); Chris@0: Chris@0: if ($this->handle !== FALSE && ($options & STREAM_USE_PATH)) { Chris@0: $opened_path = $path; Chris@0: } Chris@0: Chris@0: return (bool) $this->handle; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Support for flock(). Chris@0: * Chris@0: * An exclusive lock attempt will be rejected, as this is a read-only stream Chris@0: * wrapper. Chris@0: * Chris@0: * @param int $operation Chris@0: * One of the following: Chris@0: * - LOCK_SH to acquire a shared lock (reader). Chris@0: * - LOCK_EX to acquire an exclusive lock (writer). Chris@0: * - LOCK_UN to release a lock (shared or exclusive). Chris@0: * - LOCK_NB if you don't want flock() to block while locking (not Chris@0: * supported on Windows). Chris@0: * Chris@0: * @return bool Chris@0: * Return FALSE for an exclusive lock (writer), as this is a read-only Chris@0: * stream wrapper. Return the result of flock() for other valid operations. Chris@0: * Defaults to TRUE if an invalid operation is passed. Chris@0: * Chris@0: * @see http://php.net/manual/streamwrapper.stream-lock.php Chris@0: */ Chris@0: public function stream_lock($operation) { Chris@0: if (in_array($operation, [LOCK_EX, LOCK_EX | LOCK_NB])) { Chris@0: trigger_error('stream_lock() exclusive lock operations not supported for read-only stream wrappers', E_USER_WARNING); Chris@0: return FALSE; Chris@0: } Chris@0: if (in_array($operation, [LOCK_SH, LOCK_UN, LOCK_SH | LOCK_NB])) { Chris@0: return flock($this->handle, $operation); Chris@0: } Chris@0: Chris@0: return TRUE; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Support for fwrite(), file_put_contents() etc. Chris@0: * Chris@0: * Data will not be written as this is a read-only stream wrapper. Chris@0: * Chris@0: * @param string $data Chris@0: * The string to be written. Chris@0: * Chris@0: * @return bool Chris@0: * FALSE as data will not be written. Chris@0: * Chris@0: * @see http://php.net/manual/streamwrapper.stream-write.php Chris@0: */ Chris@0: public function stream_write($data) { Chris@0: trigger_error('stream_write() not supported for read-only stream wrappers', E_USER_WARNING); Chris@0: return FALSE; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Support for fflush(). Chris@0: * Chris@0: * Nothing will be output to the file, as this is a read-only stream wrapper. Chris@0: * However as stream_flush is called during stream_close we should not trigger Chris@0: * an error. Chris@0: * Chris@0: * @return bool Chris@0: * FALSE, as no data will be stored. Chris@0: * Chris@0: * @see http://php.net/manual/streamwrapper.stream-flush.php Chris@0: */ Chris@0: public function stream_flush() { Chris@0: return FALSE; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: * Chris@0: * Does not change meta data as this is a read-only stream wrapper. Chris@0: */ Chris@0: public function stream_metadata($uri, $option, $value) { Chris@0: trigger_error('stream_metadata() not supported for read-only stream wrappers', E_USER_WARNING); Chris@0: return FALSE; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function stream_truncate($new_size) { Chris@0: trigger_error('stream_truncate() not supported for read-only stream wrappers', E_USER_WARNING); Chris@0: return FALSE; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Support for unlink(). Chris@0: * Chris@0: * The file will not be deleted from the stream as this is a read-only stream Chris@0: * wrapper. Chris@0: * Chris@0: * @param string $uri Chris@0: * A string containing the uri to the resource to delete. Chris@0: * Chris@0: * @return bool Chris@0: * TRUE so that file_delete() will remove db reference to file. File is not Chris@0: * actually deleted. Chris@0: * Chris@0: * @see http://php.net/manual/streamwrapper.unlink.php Chris@0: */ Chris@0: public function unlink($uri) { Chris@0: trigger_error('unlink() not supported for read-only stream wrappers', E_USER_WARNING); Chris@0: return TRUE; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Support for rename(). Chris@0: * Chris@0: * This file will not be renamed as this is a read-only stream wrapper. Chris@0: * Chris@0: * @param string $from_uri Chris@0: * The uri to the file to rename. Chris@0: * @param string $to_uri Chris@0: * The new uri for file. Chris@0: * Chris@0: * @return bool Chris@0: * FALSE as file will never be renamed. Chris@0: * Chris@0: * @see http://php.net/manual/streamwrapper.rename.php Chris@0: */ Chris@0: public function rename($from_uri, $to_uri) { Chris@0: trigger_error('rename() not supported for read-only stream wrappers', E_USER_WARNING); Chris@0: return FALSE; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Support for mkdir(). Chris@0: * Chris@0: * Directory will never be created as this is a read-only stream wrapper. Chris@0: * Chris@0: * @param string $uri Chris@0: * A string containing the URI to the directory to create. Chris@0: * @param int $mode Chris@0: * Permission flags - see mkdir(). Chris@0: * @param int $options Chris@0: * A bit mask of STREAM_REPORT_ERRORS and STREAM_MKDIR_RECURSIVE. Chris@0: * Chris@0: * @return bool Chris@0: * FALSE as directory will never be created. Chris@0: * Chris@0: * @see http://php.net/manual/streamwrapper.mkdir.php Chris@0: */ Chris@0: public function mkdir($uri, $mode, $options) { Chris@0: trigger_error('mkdir() not supported for read-only stream wrappers', E_USER_WARNING); Chris@0: return FALSE; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Support for rmdir(). Chris@0: * Chris@0: * Directory will never be deleted as this is a read-only stream wrapper. Chris@0: * Chris@0: * @param string $uri Chris@0: * A string containing the URI to the directory to delete. Chris@0: * @param int $options Chris@0: * A bit mask of STREAM_REPORT_ERRORS. Chris@0: * Chris@0: * @return bool Chris@0: * FALSE as directory will never be deleted. Chris@0: * Chris@0: * @see http://php.net/manual/streamwrapper.rmdir.php Chris@0: */ Chris@0: public function rmdir($uri, $options) { Chris@0: trigger_error('rmdir() not supported for read-only stream wrappers', E_USER_WARNING); Chris@0: return FALSE; Chris@0: } Chris@0: Chris@0: }