You are here

public static function ScanDir::scan in Gutenberg 8

Same name and namespace in other branches
  1. 8.2 src/ScanDir.php \Drupal\gutenberg\ScanDir::scan()

Scans directories.

1 call to ScanDir::scan()
gutenberg-dependencies.php in scripts/gutenberg-dependencies.php
Gets Gutenberg dependencies.

File

src/ScanDir.php, line 41

Class

ScanDir
Class ScanDir.

Namespace

Drupal\gutenberg

Code

public static function scan() {

  // Initialize defaults.
  self::$recursive = FALSE;
  self::$directories = [];
  self::$files = [];
  self::$extFilter = FALSE;

  // Check we have minimum parameters.
  if (!($args = func_get_args())) {
    die("Must provide a path string or array of path strings");
  }
  if (gettype($args[0]) != "string" && gettype($args[0]) != "array") {
    die("Must provide a path string or array of path strings");
  }

  // Check if recursive scan | default action: no sub-directories.
  if (isset($args[2]) && $args[2] == TRUE) {
    self::$recursive = TRUE;
  }

  // Was a filter on file extensions included? | default action: return all
  // file types.
  if (isset($args[1])) {
    if (gettype($args[1]) == "array") {
      self::$extFilter = array_map('strtolower', $args[1]);
    }
    elseif (gettype($args[1]) == "string") {
      self::$extFilter[] = strtolower($args[1]);
    }
  }

  // Grab path(s)
  self::verifyPaths($args[0]);
  return array_map(function ($entry) {
    return substr($entry, 3, strlen($entry) - 1);
  }, self::$files);
}