You are here

public function MediaReadOnlyStreamWrapper::stream_open in D7 Media 7

Same name and namespace in other branches
  1. 7.4 includes/MediaReadOnlyStreamWrapper.inc \MediaReadOnlyStreamWrapper::stream_open()
  2. 7.2 includes/MediaReadOnlyStreamWrapper.inc \MediaReadOnlyStreamWrapper::stream_open()
  3. 7.3 includes/MediaReadOnlyStreamWrapper.inc \MediaReadOnlyStreamWrapper::stream_open()

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

Parameters

$path: A string containing the path to the file to open.

$mode: The file mode ("r", "wb" etc.).

$options: A bit mask of STREAM_USE_PATH and STREAM_REPORT_ERRORS.

&$opened_path: A string containing the path actually opened.

Return value

TRUE if file was opened successfully.

Overrides StreamWrapperInterface::stream_open

File

includes/MediaReadOnlyStreamWrapper.inc, line 202

Class

MediaReadOnlyStreamWrapper
A base class for Resource Stream Wrappers.

Code

public function stream_open($url, $mode, $options, &$opened_url) {
  $this
    ->_debug(t('Stream open: %url', array(
    '%url' => $url,
  )));

  // We only handle Read-Only mode by default.
  if ($mode != 'r' && $mode != 'rb') {
    return $this
      ->_report_error('Attempted to open %url as mode: %mode.', array(
      '%url' => $url,
      '%mode' => $mode,
    ), $options & STREAM_REPORT_ERRORS);
  }

  // We parse a URL as youtube://v/dsyiufo34/t/cats+dogs to store
  // the relevant code(s) in our private array of parameters.
  $this->parameters = $this
    ->_parse_url($url);
  if ($this->parameters === FALSE) {
    return $this
      ->_report_error('Attempted to parse an ill-formed url: %url.', array(
      '%url' => $url,
    ), $options & STREAM_REPORT_ERRORS);
  }
  if ((bool) $this->parameters && $options & STREAM_USE_PATH) {
    $opened_url = $url;
  }
  $this
    ->_debug(t('Stream opened: %parameters', array(
    '%parameters' => print_r($this->parameters, TRUE),
  )));
  return (bool) $this->parameters;
}