You are here

public function HttpStreamWrapper::stream_open in Remote Stream Wrapper 8

Return value

bool

Overrides PhpStreamWrapperInterface::stream_open

File

src/StreamWrapper/HttpStreamWrapper.php, line 129

Class

HttpStreamWrapper
HTTP(s) stream wrapper.

Namespace

Drupal\remote_stream_wrapper\StreamWrapper

Code

public function stream_open($path, $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 HTTP stream wrappers', E_USER_WARNING);
    }
    return FALSE;
  }
  try {
    $this
      ->setUri($path);
    $this
      ->request();
  } catch (\Exception $e) {
    if ($options & STREAM_REPORT_ERRORS) {

      // TODO: Make this testable.
      watchdog_exception('remote_stream_wrapper', $e);
    }
    return FALSE;
  }
  if ($options & STREAM_USE_PATH) {
    $opened_path = $path;
  }
  return TRUE;
}