function _drush_add_commandfiles

8.0.x command.inc _drush_add_commandfiles($searchpath, $phase = NULL, $reset = FALSE)
6.x command.inc _drush_add_commandfiles($searchpath, $phase = NULL, $reset = FALSE)
7.x command.inc _drush_add_commandfiles($searchpath, $phase = NULL, $reset = FALSE)
4.x command.inc _drush_add_commandfiles($searchpath, $phase = NULL)
5.x command.inc _drush_add_commandfiles($searchpath, $phase = NULL, $reset = FALSE)
master command.inc _drush_add_commandfiles($searchpath, $phase = NULL, $reset = FALSE)
2 calls to _drush_add_commandfiles()
drush_pm_enable_validate in commands/pm/pm.drush.inc
Validate callback. Determine the modules and themes that the user would like enabled.
_drush_find_commandfiles in includes/command.inc

File

includes/command.inc, line 1028
The drush command engine.

Code

function _drush_add_commandfiles($searchpath, $phase = NULL) {
  $cache = &drush_get_context('DRUSH_COMMAND_FILES', array());

  static $evaluated = array();
  static $deferred = array();

  if (sizeof($searchpath)) {
    // Build a list of all of the modules to attempt to load.
    // Start with any modules deferred from a previous phase.
    $list = $deferred;

    // Scan for drush command files; add to list for consideration if found.
    foreach (array_unique($searchpath) as $path) {
      if (is_dir($path)) {
        $nomask = array_merge(drush_filename_blacklist(), drush_get_option_list('ignored-modules'));
        $dmv = DRUSH_MAJOR_VERSION;
        $files = drush_scan_directory($path, "/\.drush($dmv|)\.inc$/", $nomask);
        foreach ($files as $filename => $info) {
          $module = basename($filename);
          $module = str_replace(array('.drush.inc', ".drush$dmv.inc"), '', $module);
          // Only try to bootstrap modules that we have never seen before, or that we
          // have tried to load but did not due to an unmet _drush_load() requirement.
          if (!array_key_exists($module, $evaluated) && file_exists($filename)) {
            $evaluated[$module] = TRUE;
            $list[$module] = $filename;
          }
        }
      }
    }

    // Check each file in the consideration list; if there is
    // a modulename_drush_load() function in modulename.drush.load.inc,
    // then call it to determine if this file should be loaded.
    foreach ($list as $module => $filename) {
      $load_command = TRUE;
      $load_test_inc = dirname($filename) . "/" . $module . ".drush.load.inc";
      if (file_exists($load_test_inc)) {
        include_once ($load_test_inc);
        $load_test_func = $module . "_drush_load";
        if (function_exists($load_test_func)) {
          $load_command = $load_test_func($phase);
        }
      }
      if ($load_command) {
        require_once realpath($filename);
        unset($deferred[$module]);
      }
      else {
        unset($list[$module]);
        // Signal that we should try again on
        // the next bootstrap phase.  We set
        // the flag to the filename of the first
        // module we find so that only that one
        // will be retried.
        $deferred[$module] = $filename;
      }
    }

    if (sizeof($list)) {
      $cache = array_merge($cache, $list);
      ksort($cache);
    }
  }
}