Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. vfsStreamWrapper.php

function 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

File

vendor/mikey179/vfsstream/src/main/php/org/bovigo/vfs/vfsStreamWrapper.php, line 285

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

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal