You are here

protected function DirectoryFetcher::listFiles in Feeds 8.3

Returns an array of files in a directory.

Parameters

string $dir: A stream wrapper URI that is a directory.

Return value

string[] An array of stream wrapper URIs pointing to files.

1 call to DirectoryFetcher::listFiles()
DirectoryFetcher::fetch in src/Feeds/Fetcher/DirectoryFetcher.php
Fetch content from a feed and return it.

File

src/Feeds/Fetcher/DirectoryFetcher.php, line 72

Class

DirectoryFetcher
Defines a directory fetcher.

Namespace

Drupal\feeds\Feeds\Fetcher

Code

protected function listFiles($dir) {
  $flags = \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS;
  if ($this->configuration['recursive_scan']) {
    $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir, $flags));
  }
  else {
    $iterator = new \FilesystemIterator($dir, $flags);
  }
  $files = [];
  foreach ($iterator as $path => $file) {
    if ($file
      ->isFile() && $file
      ->isReadable() && File::validateExtension($path, $this->configuration['allowed_extensions'])) {
      $files[] = $path;
    }
  }
  return $files;
}