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;
}