protected function SystemListing::scanDirectory

Abbreviated version of file_scan_directory().

Parameters

$dir: The base directory or URI to scan, without trailing slash.

$key: The key to be used for the returned associative array of files. Possible values are 'uri', for the file's URI; 'filename', for the basename of the file; and 'name' for the name of the file without the extension.

$mask: The preg_match() regular expression of the files to find.

$nomask: The preg_match() regular expression of the files to ignore.

Return value

array An associative array (keyed on the chosen key) of objects with 'uri', 'filename', and 'name' members corresponding to the matching files.

1 call to SystemListing::scanDirectory()
SystemListing::scan in drupal/core/lib/Drupal/Core/SystemListing.php
Returns information about system object files (modules, themes, etc.).

File

drupal/core/lib/Drupal/Core/SystemListing.php, line 167
Definition of Drupal\Core\SystemListing.

Class

SystemListing
Returns information about system object files (modules, themes, etc.).

Namespace

Drupal\Core

Code

protected function scanDirectory($dir, $key, $mask, $nomask) {
  $files = array();
  if (is_dir($dir)) {

    // Avoid warnings when opendir does not have the permissions to open a
    // directory.
    if ($handle = @opendir($dir)) {
      while (FALSE !== ($filename = readdir($handle))) {

        // Skip this file if it matches the nomask or starts with a dot.
        if ($filename[0] != '.' && !preg_match($nomask, $filename)) {
          $uri = "{$dir}/{$filename}";
          if (is_dir($uri)) {

            // Give priority to files in this folder by merging them in after
            // any subdirectory files.
            $files = array_merge($this
              ->scanDirectory($uri, $key, $mask, $nomask), $files);
          }
          elseif (preg_match($mask, $filename)) {

            // Always use this match over anything already set in $files with
            // the same $options['key'].
            $file = new \stdClass();
            $file->uri = $uri;
            $file->filename = $filename;
            $file->name = pathinfo($filename, PATHINFO_FILENAME);
            $files[$file->{$key}] = $file;
          }
        }
      }
      closedir($handle);
    }
  }
  return $files;
}