You are here

private function vfsStreamWrapper::createFile in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/mikey179/vfsStream/src/main/php/org/bovigo/vfs/vfsStreamWrapper.php \org\bovigo\vfs\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 344

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