public function S3fsStream::dir_opendir in S3 File System 4.0.x
Same name and namespace in other branches
- 8.3 src/StreamWrapper/S3fsStream.php \Drupal\s3fs\StreamWrapper\S3fsStream::dir_opendir()
- 8.2 src/StreamWrapper/S3fsStream.php \Drupal\s3fs\StreamWrapper\S3fsStream::dir_opendir()
Open directory handle.
This method is called in response to opendir().
Parameters
string $path: Specifies the URL that was passed to opendir().
int $options: Whether or not to enforce safe_mode (0x04).
Return value
bool Returns TRUE on success or FALSE on failure.
Overrides PhpStreamWrapperInterface::dir_opendir
See also
opendir()
http://php.net/manual/en/streamwrapper.dir-opendir.php
File
- src/
StreamWrapper/ S3fsStream.php, line 1084
Class
- S3fsStream
- Defines a Drupal s3 (s3://) stream wrapper class.
Namespace
Drupal\s3fs\StreamWrapperCode
public function dir_opendir($uri, $options = NULL) {
// phpcs:enable
if (!$this
->isDir($uri)) {
return FALSE;
}
$scheme = StreamWrapperManager::getScheme($uri);
$base_path = rtrim($uri, '/');
$slash_path = $base_path . '/';
// If this path was originally a root folder (e.g. s3://), the above code
// removed *both* slashes but only added one back. So we need to add
// back the second slash.
if ($slash_path == "{$scheme}:/") {
$slash_path = "{$scheme}://";
}
// Get the list of paths for files and folders which are children of the
// specified folder, but not grandchildren.
$query = \Drupal::database()
->select('s3fs_file', 's');
$query
->fields('s', [
'uri',
]);
$query
->condition('uri', $query
->escapeLike($slash_path) . '%', 'LIKE');
$query
->condition('uri', $query
->escapeLike($slash_path) . '%/%', 'NOT LIKE');
$child_paths = $query
->execute()
->fetchCol(0);
$this->dir = [];
foreach ($child_paths as $child_path) {
$this->dir[] = basename($child_path);
}
return TRUE;
}