@@ -198,14 +198,14 @@ public function addEnvironment(Environment $environment)
198198 }
199199
200200 /**
201- * Unused. See PreflightArgs::applyToConfig() instead .
201+ * Add config paths defined in preflight configuration .
202202 *
203- * @param array $preflightConfig
203+ * @param array $paths
204204 * @return $this
205205 */
206- public function addPreflightConfig ( $ preflightConfig )
206+ public function addPreflightConfigFiles ( $ filepaths )
207207 {
208- $ this ->config -> addContext (self ::PREFLIGHT_CONTEXT , $ preflightConfig );
208+ $ this ->addConfigPaths (self ::PREFLIGHT_CONTEXT , $ filepaths );
209209 return $ this ;
210210 }
211211
@@ -290,19 +290,27 @@ public function addSitewideConfig($siteRoot)
290290 */
291291 public function addConfigPaths ($ contextName , $ paths )
292292 {
293+ // Separate $paths into files and directories.
294+ list ($ files , $ dirs ) = $ this ->separateFilesAndDirs ($ paths );
295+
293296 $ loader = new YamlConfigLoader ();
297+ // Make all of the config values parsed so far available in evaluations.
298+ $ reference = $ this ->config ()->export ();
299+ $ processor = new ConfigProcessor ();
300+ $ context = $ this ->config ->getContext ($ contextName );
301+ $ processor ->add ($ context ->export ());
302+
303+ // Add config files in $dirs that match filenames in $candidates.
294304 $ candidates = [
295305 'drush.yml ' ,
296306 'config/drush.yml ' ,
297307 ];
308+ $ this ->addConfigCandidates ($ processor , $ loader , $ dirs , $ candidates );
298309
299- // Make all of the config values parsed so far available in evaluations
300- $ reference = $ this ->config ()-> export ( );
310+ // Add explicitly defined config files.
311+ $ this ->addConfigFiles ( $ processor , $ loader , $ files );
301312
302- $ processor = new ConfigProcessor ();
303- $ context = $ this ->config ->getContext ($ contextName );
304- $ processor ->add ($ context ->export ());
305- $ this ->addConfigCandidates ($ processor , $ loader , $ paths , $ candidates );
313+ // Complete config import.
306314 $ this ->addToSources ($ processor ->sources ());
307315 $ context ->import ($ processor ->export ($ reference ));
308316 $ this ->config ->addContext ($ contextName , $ context );
@@ -311,7 +319,7 @@ public function addConfigPaths($contextName, $paths)
311319 }
312320
313321 /**
314- * Worker function for addConfigPaths
322+ * Adds config files in $paths matching filenames in $candidates.
315323 *
316324 * @param ConfigProcessor $processor
317325 * @param ConfigLoaderInterface $loader
@@ -327,6 +335,21 @@ protected function addConfigCandidates(ConfigProcessor $processor, ConfigLoaderI
327335 }
328336 }
329337
338+ /**
339+ * Adds $configFiles config files.
340+ *
341+ * @param ConfigProcessor $processor
342+ * @param ConfigLoaderInterface $loader
343+ * @param array $configFiles
344+ */
345+ protected function addConfigFiles (ConfigProcessor $ processor , ConfigLoaderInterface $ loader , array $ configFiles )
346+ {
347+ foreach ($ configFiles as $ configFile ) {
348+ $ processor ->extend ($ loader ->load ($ configFile ));
349+ $ this ->configFilePaths [] = $ configFile ;
350+ }
351+ }
352+
330353 /**
331354 * Given a list of paths, and candidates that might exist at each path,
332355 * return all of the candidates that can be found. Candidates may be
@@ -478,4 +501,29 @@ public function setComposerRoot($selectedComposerRoot)
478501 {
479502 $ this ->composerRoot = $ selectedComposerRoot ;
480503 }
504+
505+ /**
506+ * Given an array of paths, separates files and directories.
507+ *
508+ * @param array $paths
509+ *
510+ * @return array
511+ * An array. The first row is an array of files, the second row is an
512+ * array of dirs.
513+ */
514+ protected function separateFilesAndDirs ($ paths ) {
515+ $ files = [];
516+ $ dirs = [];
517+ foreach ($ paths as $ path ) {
518+ if (file_exists ($ path )) {
519+ if (is_dir ($ path )) {
520+ $ dirs [] = realpath ($ path );
521+ }
522+ else {
523+ $ files [] = realpath ($ path );
524+ }
525+ }
526+ }
527+ return array ($ files , $ dirs );
528+ }
481529}
0 commit comments