You are here

public function S3fsStream::dir_opendir in S3 File System 8.3

Same name and namespace in other branches
  1. 8.2 src/StreamWrapper/S3fsStream.php \Drupal\s3fs\StreamWrapper\S3fsStream::dir_opendir()
  2. 4.0.x src/StreamWrapper/S3fsStream.php \Drupal\s3fs\StreamWrapper\S3fsStream::dir_opendir()

Return value

bool

Overrides PhpStreamWrapperInterface::dir_opendir

File

src/StreamWrapper/S3fsStream.php, line 1084

Class

S3fsStream
Defines a Drupal s3 (s3://) stream wrapper class.

Namespace

Drupal\s3fs\StreamWrapper

Code

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;
}