Skip to content

Commit

Permalink
Fixes #3994: Get environment detector subclass results on bootstrap. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
danepowell committed Feb 21, 2020
1 parent 40c7a78 commit 712b179
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/Robo/Common/EnvironmentDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,31 @@ public static function getAcsfDbName() {
return isset($GLOBALS['gardens_site_settings']) && self::isAcsfEnv() ? $GLOBALS['gardens_site_settings']['conf']['acsf_db_name'] : NULL;
}

/**
* Find the repo root.
*
* This isn't as trivial as it sounds, since a simple relative path
* (__DIR__ . '/../../../../../../') won't work if this package is symlinked
* using a Composer path repository, and this file can be invoked from both
* web requests and BLT CLI calls.
*
* @return string
* The repo root as an absolute path.
*/
public static function getRepoRoot() {
if (defined('DRUPAL_ROOT')) {
// This is a web or Drush request.
return DRUPAL_ROOT . '/..';
}
else {
// This is a BLT CLI call. Get the $repo_root that was set in
// bin/blt-robo.php.
// phpcs:ignore
global $repo_root;
return $repo_root;
}
}

/**
* Call a given function in all EnvironmentDetector subclasses.
*
Expand All @@ -348,11 +373,7 @@ public static function getAcsfDbName() {
* @throws \ReflectionException
*/
private static function getSubclassResults($functionName) {
if (!defined('DRUPAL_ROOT')) {
// Do nothing if called outside of a Drupal bootstrap.
return [];
}
$autoloader = require DRUPAL_ROOT . '/autoload.php';
$autoloader = require self::getRepoRoot() . '/vendor/autoload.php';
$classMap = $autoloader->getClassMap();
$detectors = array_filter($classMap, function ($classPath) {
return strpos($classPath, 'Blt/Plugin/EnvironmentDetector') !== FALSE;
Expand Down

0 comments on commit 712b179

Please sign in to comment.