You are here

public function LocalStream::stream_metadata in System stream wrapper 8

Sets metadata on the stream.

Parameters

string $path: A string containing the URI to the file to set metadata on.

int $option: One of:

  • STREAM_META_TOUCH: The method was called in response to touch().
  • STREAM_META_OWNER_NAME: The method was called in response to chown() with string parameter.
  • STREAM_META_OWNER: The method was called in response to chown().
  • STREAM_META_GROUP_NAME: The method was called in response to chgrp().
  • STREAM_META_GROUP: The method was called in response to chgrp().
  • STREAM_META_ACCESS: The method was called in response to chmod().

mixed $value: If option is:

  • STREAM_META_TOUCH: Array consisting of two arguments of the touch() function.
  • STREAM_META_OWNER_NAME or STREAM_META_GROUP_NAME: The name of the owner user/group as string.
  • STREAM_META_OWNER or STREAM_META_GROUP: The value of the owner user/group as integer.
  • STREAM_META_ACCESS: The argument of the chmod() as integer.

Return value

bool Returns TRUE on success or FALSE on failure. If $option is not implemented, FALSE should be returned.

Overrides PhpStreamWrapperInterface::stream_metadata

See also

http://php.net/manual/streamwrapper.stream-metadata.php

1 method overrides LocalStream::stream_metadata()
LocalReadOnlyStream::stream_metadata in src/StreamWrapper/LocalReadOnlyStream.php
Does not change meta data as this is a read-only stream wrapper.

File

src/StreamWrapper/LocalStream.php, line 250

Class

LocalStream
Defines a Drupal stream wrapper base class for local files.

Namespace

Drupal\system_stream_wrapper\StreamWrapper

Code

public function stream_metadata($uri, $option, $value) {
  $target = $this
    ->getLocalPath($uri);
  $return = FALSE;
  switch ($option) {
    case STREAM_META_TOUCH:
      if (!empty($value)) {
        $return = touch($target, $value[0], $value[1]);
      }
      else {
        $return = touch($target);
      }
      break;
    case STREAM_META_OWNER_NAME:
    case STREAM_META_OWNER:
      $return = chown($target, $value);
      break;
    case STREAM_META_GROUP_NAME:
    case STREAM_META_GROUP:
      $return = chgrp($target, $value);
      break;
    case STREAM_META_ACCESS:
      $return = chmod($target, $value);
      break;
  }
  if ($return) {

    // For convenience clear the file status cache of the underlying file,
    // since metadata operations are often followed by file status checks.
    clearstatcache(TRUE, $target);
  }
  return $return;
}