1 file_example_session_streams.inc public FileExampleSessionStreamWrapper::url_stat($uri, $flags)

Support for stat().

This important function goes back to the Unix way of doing things. In this example almost the entire stat array is irrelevant, but the mode is very important. It tells PHP whether we have a file or a directory and what the permissions are. All that is packed up in a bitmask. This is not normal PHP fodder.

Parameters

string $uri: A string containing the URI to get information about.

int $flags: A bit mask of STREAM_URL_STAT_LINK and STREAM_URL_STAT_QUIET.

Return value

array|bool: An array with file status, or FALSE in case of an error - see fstat() for a description of this array.

Overrides StreamWrapperInterface::url_stat

See also

http://php.net/manual/en/streamwrapper.url-stat.php

File

modules/examples/file_example/file_example_session_streams.inc, line 598
Provides a demonstration session:// stream-wrapper.

Class

FileExampleSessionStreamWrapper
Example stream wrapper class to handle session:// streams.

Code

public function url_stat($uri, $flags) {
  // Get a reference to the $_SESSION key for this URI.
  $key = $this->uri_to_session_key($uri, FALSE);
  // Default to fail.
  $return = FALSE;
  $mode = 0;

  // We will call an array a directory and the root is always an array.
  if (is_array($key) && array_key_exists('.isadir.txt', $key)) {
    // S_IFDIR means it's a directory.
    $mode = 0040000;
  }
  elseif ($key !== FALSE) {
    // S_IFREG means it's a file.
    $mode = 0100000;
  }

  if ($mode) {
    $size = 0;
    if ($mode == 0100000) {
      $size = backdrop_strlen($key);
    }

    // There are no protections on this, so all writable.
    $mode |= 0777;
    $return = array(
      'dev' => 0,
      'ino' => 0,
      'mode' => $mode,
      'nlink' => 0,
      'uid' => 0,
      'gid' => 0,
      'rdev' => 0,
      'size' => $size,
      'atime' => 0,
      'mtime' => 0,
      'ctime' => 0,
      'blksize' => 0,
      'blocks' => 0,
    );
  }

  return $return;
}