diff --git a/src/Config/ConfigLocator.php b/src/Config/ConfigLocator.php index e43863f7e8..9edce2d644 100644 --- a/src/Config/ConfigLocator.php +++ b/src/Config/ConfigLocator.php @@ -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; } @@ -290,19 +290,27 @@ 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', ]; + $this->addConfigCandidates($processor, $loader, $dirs, $candidates); - // 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); @@ -311,7 +319,7 @@ public function addConfigPaths($contextName, $paths) } /** - * Worker function for addConfigPaths + * Adds config files in $paths matching filenames in $candidates. * * @param ConfigProcessor $processor * @param ConfigLoaderInterface $loader @@ -327,6 +335,21 @@ protected function addConfigCandidates(ConfigProcessor $processor, ConfigLoaderI } } + /** + * Adds $configFiles config files. + * + * @param ConfigProcessor $processor + * @param ConfigLoaderInterface $loader + * @param array $configFiles + */ + protected function addConfigFiles(ConfigProcessor $processor, ConfigLoaderInterface $loader, array $configFiles) + { + foreach ($configFiles as $configFile) { + $processor->extend($loader->load($configFile)); + $this->configFilePaths[] = $configFile; + } + } + /** * Given a list of paths, and candidates that might exist at each path, * return all of the candidates that can be found. Candidates may be @@ -478,4 +501,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); + } + else { + $files[] = realpath($path); + } + } + } + return array($files, $dirs); + } } diff --git a/src/Preflight/Preflight.php b/src/Preflight/Preflight.php index d55ef51537..726f2dea45 100644 --- a/src/Preflight/Preflight.php +++ b/src/Preflight/Preflight.php @@ -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());