function commandfile_searchpaths($phase, $phase_max = FALSE) { if (!$phase_max) { $phase_max = $phase; } $container = \Drush::getContainer(); $discovery = $container->get('commandDiscovery'); $commandFiles = []; $searchpath = []; switch ($phase) { case DRUSH_BOOTSTRAP_DRUPAL_ROOT: $drupal_root = \Drush::bootstrapManager()->getRoot(); $searchpath[] = $drupal_root . '/../drush'; $searchpath[] = $drupal_root . '/drush'; $searchpath[] = $drupal_root . '/sites/all/drush'; $commandFiles = $discovery->discover($searchpath, '\\Drupal'); 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 extension 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 = array_merge($searchpath, $this->contrib_modules_paths()); // 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 kinda dodgy. $cid = drush_cid_install_profile(); if ($cached = drush_cache_get($cid)) { $profile = $cached->data; $searchpath[] = "profiles/{$profile}/modules"; $searchpath[] = "profiles/{$profile}/themes"; } else { // If install_profile is not available, scan all profiles. $searchpath[] = "profiles"; $searchpath[] = "sites/all/profiles"; } $searchpath = array_merge($searchpath, $this->contrib_themes_paths()); // Drupal 8 uses the modules' services files to find commandfiles. Should we allow // redundant find-module-by-location for Drupal 8? (Maybe not.) if (drush_drupal_major_version() < 8) { $commandFiles = $discovery->discoverNamespaced($searchpath, '\\Drupal'); } } break; case DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION: // Nothing to do here anymore. Left for documentation. break; case DRUSH_BOOTSTRAP_DRUPAL_FULL: // Add enabled module paths, excluding 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(drush_module_list(), $ignored_modules) as $module) { $filepath = drupal_get_path('module', $module); if ($filepath && $filepath != '/') { $searchpath[] = $filepath; } } // Check all enabled themes including non-default and non-admin. foreach (drush_theme_list() as $key => $value) { $searchpath[] = drupal_get_path('theme', $key); } // Drupal 8 uses the modules' services files to find commandfiles. Should we allow // redundant find-module-by-location for Drupal 8? (Maybe not.) if (drush_drupal_major_version() < 8) { $commandFiles = $discovery->discoverNamespaced($searchpath, '\\Drupal'); } break; } // A little inelegant, but will do for now. drush_init_register_command_files($container, $commandFiles); return $searchpath; }
function commandfile_searchpaths($phase, $phase_max = FALSE) { if (!$phase_max) { $phase_max = $phase; } $searchpath = array(); switch ($phase) { case DRUSH_BOOTSTRAP_DRUPAL_ROOT: $drupal_root = drush_get_context('DRUSH_SELECTED_DRUPAL_ROOT'); $searchpath[] = $drupal_root . '/../drush'; $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 extension 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 = array_merge($searchpath, $this->contrib_modules_paths()); // 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 kinda dodgy. $cid = drush_cid_install_profile(); if ($cached = drush_cache_get($cid)) { $profile = $cached->data; $searchpath[] = "profiles/{$profile}/modules"; $searchpath[] = "profiles/{$profile}/themes"; } else { // If install_profile is not available, scan all profiles. $searchpath[] = "profiles"; $searchpath[] = "sites/all/profiles"; } $searchpath = array_merge($searchpath, $this->contrib_themes_paths()); } break; case DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION: // Nothing to do here anymore. Left for documentation. break; case DRUSH_BOOTSTRAP_DRUPAL_FULL: // Add enabled module paths, excluding 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(drush_module_list(), $ignored_modules) as $module) { $filepath = drupal_get_path('module', $module); if ($filepath && $filepath != '/') { $searchpath[] = $filepath; } } // Check all enabled themes including non-default and non-admin. foreach (drush_theme_list() as $key => $value) { $searchpath[] = drupal_get_path('theme', $key); } break; } return $searchpath; }