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

Breadcrumb

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

function vfsStreamWrapper::createFile

creates a file at given path

Parameters

string $path the path to open:

string $mode mode for opening:

string $options options for opening:

Return value

bool

2 calls to vfsStreamWrapper::createFile()
vfsStreamWrapper::stream_metadata in vendor/mikey179/vfsstream/src/main/php/org/bovigo/vfs/vfsStreamWrapper.php
sets metadata like owner, user or permissions
vfsStreamWrapper::stream_open in vendor/mikey179/vfsstream/src/main/php/org/bovigo/vfs/vfsStreamWrapper.php
open the stream

File

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

Class

vfsStreamWrapper
Stream wrapper to mock file system requests.

Namespace

org\bovigo\vfs

Code

private function createFile($path, $mode = null, $options = null) {
    $names = $this->splitPath($path);
    if (empty($names['dirname']) === true) {
        if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) {
            trigger_error('File ' . $names['basename'] . ' does not exist', E_USER_WARNING);
        }
        return false;
    }
    $dir = $this->getContentOfType($names['dirname'], vfsStreamContent::TYPE_DIR);
    if (null === $dir) {
        if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) {
            trigger_error('Directory ' . $names['dirname'] . ' does not exist', E_USER_WARNING);
        }
        return false;
    }
    elseif ($dir->hasChild($names['basename']) === true) {
        if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) {
            trigger_error('Directory ' . $names['dirname'] . ' already contains a director named ' . $names['basename'], E_USER_WARNING);
        }
        return false;
    }
    if (self::READ === $mode) {
        if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) {
            trigger_error('Can not open non-existing file ' . $path . ' for reading', E_USER_WARNING);
        }
        return false;
    }
    if ($dir->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup()) === false) {
        if (($options & STREAM_REPORT_ERRORS) === STREAM_REPORT_ERRORS) {
            trigger_error('Can not create new file in non-writable path ' . $names['dirname'], E_USER_WARNING);
        }
        return false;
    }
    return vfsStream::newFile($names['basename'])->at($dir);
}

API Navigation

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