You are here

public function vfsStreamWrapper::stream_metadata 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::stream_metadata()

sets metadata like owner, user or permissions

@since 1.1.0

Parameters

string $path:

int $option:

mixed $var:

Return value

bool

File

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

Class

vfsStreamWrapper
Stream wrapper to mock file system requests.

Namespace

org\bovigo\vfs

Code

public function stream_metadata($path, $option, $var) {
  $path = $this
    ->resolvePath(vfsStream::path($path));
  $content = $this
    ->getContent($path);
  switch ($option) {
    case STREAM_META_TOUCH:
      if (null === $content) {
        $content = $this
          ->createFile($path, null, STREAM_REPORT_ERRORS);

        // file creation may not be allowed at provided path
        if (false === $content) {
          return false;
        }
      }
      $currentTime = time();
      $content
        ->lastModified(isset($var[0]) ? $var[0] : $currentTime)
        ->lastAccessed(isset($var[1]) ? $var[1] : $currentTime);
      return true;
    case STREAM_META_OWNER_NAME:
      return false;
    case STREAM_META_OWNER:
      if (null === $content) {
        return false;
      }
      return $this
        ->doPermChange($path, $content, function () use ($content, $var) {
        $content
          ->chown($var);
      });
    case STREAM_META_GROUP_NAME:
      return false;
    case STREAM_META_GROUP:
      if (null === $content) {
        return false;
      }
      return $this
        ->doPermChange($path, $content, function () use ($content, $var) {
        $content
          ->chgrp($var);
      });
    case STREAM_META_ACCESS:
      if (null === $content) {
        return false;
      }
      return $this
        ->doPermChange($path, $content, function () use ($content, $var) {
        $content
          ->chmod($var);
      });
    default:
      return false;
  }
}