Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 47 additions & 15 deletions src/Config/ConfigLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,14 @@ public function addEnvironment(Environment $environment)
}

/**
* Unused. See PreflightArgs::applyToConfig() instead.
* Add config paths defined in preflight configuration.
*
* @param array $preflightConfig
* @param array $paths
* @return $this
*/
public function addPreflightConfig($preflightConfig)
public function addPreflightConfigFiles($filepaths)
{
$this->config->addContext(self::PREFLIGHT_CONTEXT, $preflightConfig);
$this->addConfigPaths(self::PREFLIGHT_CONTEXT, (array) $filepaths);
return $this;
}

Expand Down Expand Up @@ -290,19 +290,28 @@ public function addSitewideConfig($siteRoot)
*/
public function addConfigPaths($contextName, $paths)
{
// Separate $paths into files and directories.
list($files, $dirs) = $this->separateFilesAndDirs($paths);

$loader = new YamlConfigLoader();
// Make all of the config values parsed so far available in evaluations.
$reference = $this->config()->export();
$processor = new ConfigProcessor();
$context = $this->config->getContext($contextName);
$processor->add($context->export());

// Add config files in $dirs that match filenames in $candidates.
$candidates = [
'drush.yml',
'config/drush.yml',
];
$discovered_config_files = $this->identifyCandidates($dirs, $candidates);
$this->addConfigFiles($processor, $loader, $discovered_config_files);

// Make all of the config values parsed so far available in evaluations
$reference = $this->config()->export();
// Add explicitly defined config files.
$this->addConfigFiles($processor, $loader, $files);

$processor = new ConfigProcessor();
$context = $this->config->getContext($contextName);
$processor->add($context->export());
$this->addConfigCandidates($processor, $loader, $paths, $candidates);
// Complete config import.
$this->addToSources($processor->sources());
$context->import($processor->export($reference));
$this->config->addContext($contextName, $context);
Expand All @@ -311,16 +320,14 @@ public function addConfigPaths($contextName, $paths)
}

/**
* Worker function for addConfigPaths
* Adds $configFiles config files.
*
* @param ConfigProcessor $processor
* @param ConfigLoaderInterface $loader
* @param string[] $paths
* @param string[] $candidates
* @param array $configFiles
*/
protected function addConfigCandidates(ConfigProcessor $processor, ConfigLoaderInterface $loader, $paths, $candidates)
protected function addConfigFiles(ConfigProcessor $processor, ConfigLoaderInterface $loader, array $configFiles)
{
$configFiles = $this->identifyCandidates($paths, $candidates);
foreach ($configFiles as $configFile) {
$processor->extend($loader->load($configFile));
$this->configFilePaths[] = $configFile;
Expand Down Expand Up @@ -478,4 +485,29 @@ public function setComposerRoot($selectedComposerRoot)
{
$this->composerRoot = $selectedComposerRoot;
}

/**
* Given an array of paths, separates files and directories.
*
* @param array $paths
*
* @return array
* An array. The first row is an array of files, the second row is an
* array of dirs.
*/
protected function separateFilesAndDirs($paths) {
$files = [];
$dirs = [];
foreach ($paths as $path) {
if (file_exists($path)) {
if (is_dir($path)) {
$dirs[] = realpath($path);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you pass in $candidates to this function then you could call $this->identifyCandidates($dirs, $candidates); here (or at the end of this function). This would allow you to keep $dirs private to this method and return only $files.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This improvement would of course imply a renaming of this method.

}
else {
$files[] = realpath($path);
}
}
}
return array($files, $dirs);
}
}
1 change: 0 additions & 1 deletion src/Preflight/Preflight.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ public function prepareConfig(Environment $environment)
{
// Make our environment settings available as configuration items
$this->configLocator->addEnvironment($environment);

$this->configLocator->setLocal($this->preflightArgs->isLocal());
$this->configLocator->addUserConfig($this->preflightArgs->configPaths(), $environment->systemConfigPath(), $environment->userConfigPath());
$this->configLocator->addDrushConfig($environment->drushBasePath());
Expand Down