public function SessionStreamWrapper::url_stat in Examples for Developers 3.x
Same name and namespace in other branches
- 8 stream_wrapper_example/src/StreamWrapper/SessionStreamWrapper.php \Drupal\stream_wrapper_example\StreamWrapper\SessionStreamWrapper::url_stat()
Retrieve information about a file.
This method is called in response to all stat() related functions.
Note, the streamWrapper::$context property is updated if a valid context is passed to the caller function.
Parameters
string $path: The file path or URL to stat. Note that in the case of a URL, it must be a "://" delimited URL. Other URL forms are not supported.
int $flags: Holds additional flags set by the streams API. It can hold one or more of the following values ORed together:
- STREAM_URL_STAT_LINK: For resources with the ability to link to other resource (such as an HTTP Location: forward, or a filesystem symlink). This flag specified that only information about the link itself should be returned, not the resource pointed to by the link. This flag is set in response to calls to lstat(), is_link(), or filetype().
- STREAM_URL_STAT_QUIET: If this flag is set, your wrapper should not raise any errors. If this flag is not set, you are responsible for reporting errors using the trigger_error() function during stating of the path.
Return value
array|false Should return the same as stat() does. Unknown or unavailable values should be set to a rational value (usually 0).
Overrides PhpStreamWrapperInterface::url_stat
See also
stat()
PhpStreamWrapperInterface::stream_stat()
http://php.net/manual/en/streamwrapper.url-stat.php
File
- modules/
stream_wrapper_example/ src/ StreamWrapper/ SessionStreamWrapper.php, line 741
Class
- SessionStreamWrapper
- Example stream wrapper class to handle session:// streams.
Namespace
Drupal\stream_wrapper_example\StreamWrapperCode
public function url_stat($uri, $flags) {
// @codingStandardsIgnoreEnd
$path = $this
->getLocalPath($uri);
if (!$this->sessionHelper
->checkPath($path)) {
return FALSE;
// No file.
}
// Default to fail.
$return = FALSE;
$mode = 0;
$key = $this->sessionHelper
->getPath($path);
// We will call an array a directory and the root is always an array.
if (is_array($key)) {
// S_IFDIR means it's a directory.
$mode = 040000;
}
elseif ($key !== FALSE) {
// S_IFREG, means it's a file.
$mode = 0100000;
}
if ($mode) {
$size = 0;
if ($mode == 0100000) {
$size = strlen($key);
}
// There are no protections on this, so all writable.
$mode |= 0777;
$return = [
'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;
}