function _drush_find_commandfiles

8.0.x command.inc _drush_find_commandfiles($phase, $phase_max = FALSE)
6.x command.inc _drush_find_commandfiles($phase, $phase_max = FALSE)
7.x command.inc _drush_find_commandfiles($phase, $phase_max = FALSE)
3.x command.inc _drush_find_commandfiles($phase)
4.x command.inc _drush_find_commandfiles($phase, $phase_max = FALSE)
5.x command.inc _drush_find_commandfiles($phase, $phase_max = FALSE)
master command.inc _drush_find_commandfiles($phase, $phase_max = FALSE)
2 calls to _drush_find_commandfiles()
drush_bootstrap in includes/bootstrap.inc
Bootstrap Drush to the desired phase.
drush_command_belongs_to_disabled_module in ./drush.php
Check if the given command belongs to a disabled module

File

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

Code

function _drush_find_commandfiles($phase, $phase_max = FALSE) {
  if (!$phase_max) {
    $phase_max = $phase;
  }

  $searchpath = array();
  switch ($phase) {
    case DRUSH_BOOTSTRAP_DRUSH:
      // Core commands shipping with drush
      $searchpath[] = realpath(dirname(__FILE__) . '/../commands/');

      // User commands, specified by 'include' option
      if ($include = drush_get_context('DRUSH_INCLUDE', FALSE)) {
        foreach ($include as $path) {
          if (is_dir($path)) {
            drush_log('Include ' . $path, 'notice');
            $searchpath[] = $path;
          }
        }
      }

      // System commands, residing in $SHARE_PREFIX/share/drush/commands
      $share_path = drush_get_context('DRUSH_SITE_WIDE_COMMANDFILES');
      if (is_dir($share_path)) {
        $searchpath[] = $share_path;
      }

      // User commands, residing in ~/.drush
      $per_user_config_dir = drush_get_context('DRUSH_PER_USER_CONFIGURATION');
      if (!empty($per_user_config_dir)) {
        $searchpath[] = $per_user_config_dir;
      }

      // Include commandfiles located in Drupal's /drush and sites/all/drush even before root is bootstrapped.
      if ($drupal_root = drush_get_context('DRUSH_SELECTED_DRUPAL_ROOT')) {
        $searchpath[] = $drupal_root . '/drush';
        $searchpath[] = $drupal_root . '/sites/all/drush';
      }
      break;
    case DRUSH_BOOTSTRAP_DRUPAL_SITE:
      // If we are going to stop bootstrapping at the site, then
      // we will quickly add all commandfiles that we can find for
      // any module associated with the site, whether it is enabled
      // or not.  If we are, however, going to continue on to bootstrap
      // all the way to DRUSH_BOOTSTRAP_DRUPAL_FULL, then we will
      // instead wait for that phase, which will more carefully add
      // only those Drush commandfiles that are associated with
      // enabled modules.
      if ($phase_max < DRUSH_BOOTSTRAP_DRUPAL_FULL) {
        $searchpath[] = conf_path() . '/modules';
        // Add all module paths, even disabled modules. Prefer speed over accuracy.
        $searchpath[] = 'sites/all/modules';
        // In D8, we search top level directories as well.
        if (drush_drupal_major_version() >= 8) {
          $searchpath[] = 'modules';
        }

        // Adding commandfiles located within /profiles. Try to limit to one profile for speed. Note
        // that Drupal allows enabling modules from a non-active profile so this logic is non-ideal.
        $cid = drush_cid_install_profile();
        if ($cached = drush_cache_get($cid)) {
          $profile = $cached->data;
          $searchpath[] = "profiles/$profile/modules";
        }
        else {
          // If install_profile is not available, scan all profiles.
          $searchpath[] = "profiles";
          $searchpath[] = "sites/all/profiles";
        }
      }

      // TODO: Treat themes like modules and stop unconditionally searching here.
      $searchpath[] = 'sites/all/themes';
      $searchpath[] = conf_path() . '/themes';
      // In D8, we search top level directories as well.
      if (drush_drupal_major_version() >= 8) {
        $searchpath[] = 'themes';
      }
      break;
    case DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION:
      // Nothing to do here anymore. Left for documentation.
      break;
    case DRUSH_BOOTSTRAP_DRUPAL_FULL:
      // Add enabled module paths, except the install profile. Since we are bootstrapped,
      // we can use the Drupal API.
      $ignored_modules = drush_get_option_list('ignored-modules', array());
      $cid = drush_cid_install_profile();
      if ($cached = drush_cache_get($cid)) {
        $ignored_modules[] = $cached->data;
      }
      foreach (array_diff(module_list(), $ignored_modules) as $module) {
        $filename = drupal_get_filename('module', $module);
        if ($filename) {
          $searchpath[] = dirname($filename);
        }
      }
      break;
  }

  _drush_add_commandfiles($searchpath, $phase);
}