Skip to content

Commit

Permalink
move responsiblity of site alias path building to the configlocator a…
Browse files Browse the repository at this point in the history
…nd only add environment if the config is local (#2991)
  • Loading branch information
joelpittet committed Sep 30, 2017
1 parent a498ece commit 4bd002d
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 8 deletions.
38 changes: 38 additions & 0 deletions src/Config/ConfigLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Consolidation\Config\Loader\YamlConfigLoader;
use Consolidation\Config\Loader\ConfigProcessor;
use Consolidation\Config\Util\ConfigOverlay;
use Drush\Preflight\PreflightArgsInterface;

/**
* Locate Drush configuration files and load them into the configuration
Expand Down Expand Up @@ -38,6 +39,8 @@ class ConfigLocator

protected $siteRoots = [];

protected $composerRoot;

protected $configFilePaths = [];

/*
Expand Down Expand Up @@ -78,6 +81,7 @@ class ConfigLocator
// home.drush is obsolete (loaded in USER_CONTEXT)
// system context is obsolect (loaded in USER_CONTEXT - note priority change)
const DRUSH_CONTEXT = 'drush';

// 'default' context is provided by ConfigOverlay

public function __construct()
Expand Down Expand Up @@ -256,4 +260,38 @@ protected function locateConfig($path, $candidates)
}
return $result;
}

/**
* Get the site aliases with preflight arguments and environment.
*
* @param $preflightArgs
* @param Environment $environment
*
* @return array
*/
public function getSiteAliasPaths(PreflightArgsInterface $preflightArgs, Environment $environment)
{
$paths[] = $preflightArgs->aliasPath();
if (!$this->isLocal) {
$paths[] = $environment->systemConfigPath();
$paths[] = $environment->userConfigPath();
}

foreach ($this->siteRoots as $siteRoot) {
$paths[] = $siteRoot . '/drush';
}
$paths[] = $this->composerRoot . '/drush';

return $paths;
}

/**
* Sets the composer root.
*
* @param $selectedComposerRoot
*/
public function setComposerRoot($selectedComposerRoot)
{
$this->composerRoot = $selectedComposerRoot;
}
}
12 changes: 4 additions & 8 deletions src/Preflight/Preflight.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,12 @@ protected function doRun($argv)
// target site.
$root = $this->findSelectedSite($preflightArgs);
$configLocator->addSitewideConfig($root);
$configLocator->setComposerRoot($this->selectedComposerRoot());

$paths = $configLocator->getSiteAliasPaths($preflightArgs, $this->environment);

// Configure alias manager.
// TODO: We have a nice ConfigLocator that knows about --local, etc.;
// we should use that here as well.
$aliasManager = (new SiteAliasManager())
->addSearchLocation($preflightArgs->aliasPath())
->addSearchLocation($this->environment->systemConfigPath())
->addSearchLocation($this->environment->userConfigPath())
->addSearchLocation($this->selectedDrupalRoot() . '/drush')
->addSearchLocation($this->selectedComposerRoot() . '/drush');
$aliasManager = (new SiteAliasManager())->addSearchLocations($paths);
$selfAliasRecord = $aliasManager->findSelf($preflightArgs, $this->environment, $root);
$aliasConfig = $selfAliasRecord->exportConfig();
$configLocator->addAliasConfig($aliasConfig);
Expand Down
17 changes: 17 additions & 0 deletions src/SiteAlias/SiteAliasManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function setRoot($root)
* Add a search location to our site alias discovery object.
*
* @param string $path
*
* @return $this
*/
public function addSearchLocation($path)
Expand All @@ -46,6 +47,21 @@ public function addSearchLocation($path)
return $this;
}

/**
* Add search locations to our site alias discovery object.
*
* @param array $paths
*
* @return $this
*/
public function addSearchLocations(array $paths)
{
foreach ($paths as $path) {
$this->aliasLoader->discovery()->addSearchLocation($path);
}
return $this;
}

/**
* Get an alias record by name, or convert a site specification
* into an alias record via the site alias spec parser. If a
Expand Down Expand Up @@ -237,4 +253,5 @@ protected function buildSelf(PreflightArgsInterface $preflightArgs, Environment
'@self'
);
}

}

0 comments on commit 4bd002d

Please sign in to comment.