You are here

public function ResourceReadOnlyStreamWrapper::stream_open in D7 Media 6

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

resource/ResourceReadOnlyStreamWrapper.inc, line 93

Class

ResourceReadOnlyStreamWrapper
A base class for Resource Stream Wrappers.

Code

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

  // We only handle Read-Only mode by default.
  if ($mode != 'r') {
    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;
  }
  resource_debug(t('Stream opened: %parameters', array(
    '%parameters' => print_r($this->parameters, TRUE),
  )));
  return (bool) $this->parameters;
}