You are here

public function vfsStreamWrapper::stream_open in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/mikey179/vfsStream/src/main/php/org/bovigo/vfs/vfsStreamWrapper.php \org\bovigo\vfs\vfsStreamWrapper::stream_open()

open the stream

Parameters

string $path the path to open:

string $mode mode for opening:

string $options options for opening:

string $opened_path full path that was actually opened:

Return value

bool

1 call to vfsStreamWrapper::stream_open()
vfsStreamWrapperRecordingProxy::stream_open in vendor/mikey179/vfsStream/src/test/php/org/bovigo/vfs/proxy/vfsStreamWrapperRecordingProxy.php
open the stream
1 method overrides vfsStreamWrapper::stream_open()
vfsStreamWrapperRecordingProxy::stream_open in vendor/mikey179/vfsStream/src/test/php/org/bovigo/vfs/proxy/vfsStreamWrapperRecordingProxy.php
open the stream

File

vendor/mikey179/vfsStream/src/main/php/org/bovigo/vfs/vfsStreamWrapper.php, line 279

Class

vfsStreamWrapper
Stream wrapper to mock file system requests.

Namespace

org\bovigo\vfs

Code

public function stream_open($path, $mode, $options, $opened_path) {
  $extended = strstr($mode, '+') !== false ? true : false;
  $mode = str_replace(array(
    't',
    'b',
    '+',
  ), '', $mode);
  if (in_array($mode, array(
    'r',
    'w',
    'a',
    'x',
    'c',
  )) === false) {
    if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) {
      trigger_error('Illegal mode ' . $mode . ', use r, w, a, x  or c, flavoured with t, b and/or +', E_USER_WARNING);
    }
    return false;
  }
  $this->mode = $this
    ->calculateMode($mode, $extended);
  $path = $this
    ->resolvePath(vfsStream::path($path));
  $this->content = $this
    ->getContentOfType($path, vfsStreamContent::TYPE_FILE);
  if (null !== $this->content) {
    if (self::WRITE === $mode) {
      if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) {
        trigger_error('File ' . $path . ' already exists, can not open with mode x', E_USER_WARNING);
      }
      return false;
    }
    if ((self::TRUNCATE === $mode || self::APPEND === $mode) && $this->content
      ->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup()) === false) {
      return false;
    }
    if (self::TRUNCATE === $mode) {
      $this->content
        ->openWithTruncate();
    }
    elseif (self::APPEND === $mode) {
      $this->content
        ->openForAppend();
    }
    else {
      if (!$this->content
        ->isReadable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup())) {
        if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) {
          trigger_error('Permission denied', E_USER_WARNING);
        }
        return false;
      }
      $this->content
        ->open();
    }
    return true;
  }
  $content = $this
    ->createFile($path, $mode, $options);
  if (false === $content) {
    return false;
  }
  $this->content = $content;
  return true;
}