public function S3fsStream::dir_opendir in S3 File System 8.2
Same name and namespace in other branches
- 8.3 src/StreamWrapper/S3fsStream.php \Drupal\s3fs\StreamWrapper\S3fsStream::dir_opendir()
- 4.0.x src/StreamWrapper/S3fsStream.php \Drupal\s3fs\StreamWrapper\S3fsStream::dir_opendir()
Support for opendir().
Parameters
string $uri: The URI to the directory to open.
int $options: A flag used to enable safe_mode. This wrapper doesn't support safe_mode, so this parameter is ignored.
Return value
bool TRUE on success. Otherwise, FALSE.
Overrides PhpStreamWrapperInterface::dir_opendir
See also
http://php.net/manual/en/streamwrapper.dir-opendir.php
File
- src/
StreamWrapper/ S3fsStream.php, line 1024
Class
- S3fsStream
- Defines a Drupal s3fs (s3fs://) stream wrapper class.
Namespace
Drupal\s3fs\StreamWrapperCode
public function dir_opendir($uri, $options = NULL) {
$this
->_assert_constructor_called();
$this
->_debug("dir_opendir({$uri}, {$options}) called.");
if (!$this
->_uri_is_dir($uri)) {
return FALSE;
}
$scheme = \Drupal::service('file_system')
->uriScheme($uri);
$bare_uri = rtrim($uri, '/');
$slash_uri = $bare_uri . '/';
// If this URI 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_uri == "{$scheme}:/") {
$slash_uri = "{$scheme}://";
}
// Get the list of uris 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_uri) . '%', 'LIKE');
$query
->condition('uri', $query
->escapeLike($slash_uri) . '%/%', 'NOT LIKE');
$child_uris = $query
->execute()
->fetchCol(0);
$this->dir = [];
foreach ($child_uris as $child_uri) {
$this->dir[] = basename($child_uri);
}
return TRUE;
}