Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions drush.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Drush\Drush;
use Drush\Config\Environment;
use Drush\Preflight\Preflight;
use Drush\Runtime\Runtime;
Expand Down Expand Up @@ -55,6 +56,7 @@

// Set up environment
$environment = new Environment(Path::getHomeDirectory(), $cwd, $autoloadFile);
$environment->setConfigFileVariant(Drush::getMajorVersion());
$environment->setLoader($loader);
$environment->applyEnvironment();

Expand Down
7 changes: 7 additions & 0 deletions examples/example.drush.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
#
# If a configuration file is found in any of the above locations, it will be
# loaded and merged with other configuration files in the search list.
#
# Version-specific configuration
#
# Drush started using yml files for configuration in version 9; earlier versions
# of Drush will never attempt to load a drush.yml file. It is also possible
# to limit the version of Drush that will load a configuration file by placing
# the Drush major version number in the filename, e.g. drush9.yml.

# Environment variables
#
Expand Down
2 changes: 2 additions & 0 deletions isolation/fixtures/etc/drush/drushIGNORED.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
variant: 'This file should be ignored'
2 changes: 2 additions & 0 deletions isolation/fixtures/etc/drush/drushVARIANT.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
variant: 'A variable that only exists in the variant drush.yml'
3 changes: 2 additions & 1 deletion isolation/tests/ConfigLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function testLoadAll()
$sources = $configLocator->sources();
//$this->assertEquals('environment', $sources['env']['cwd']);
$this->assertEquals($this->fixturesDir() . '/etc/drush/drush.yml', $sources['test']['system']);
$this->assertEquals($this->fixturesDir() . '/etc/drush/drushVARIANT.yml', $sources['test']['variant']);
$this->assertEquals($this->fixturesDir() . '/home/.drush/drush.yml', $sources['test']['home']);
$this->assertEquals($this->fixturesDir() . '/sites/d8/drush/drush.yml', $sources['test']['site']);
$this->assertEquals($this->environment()->drushBasePath() . '/drush.yml', $sources['drush']['php']['minimum-version']);
Expand Down Expand Up @@ -90,7 +91,7 @@ function ($item) {
*/
protected function createConfigLocator($isLocal = false, $configPath = '')
{
$configLocator = new ConfigLocator('TEST_');
$configLocator = new ConfigLocator('TEST_', 'VARIANT');
$configLocator->collectSources();
$configLocator->setLocal($isLocal);
$configLocator->addUserConfig([$configPath], $this->environment()->systemConfigPath(), $this->environment()->userConfigPath());
Expand Down
24 changes: 22 additions & 2 deletions src/Config/ConfigLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class ConfigLocator

protected $configFilePaths = [];

protected $configFileVariant;

protected $processedConfigPaths = [];

/*
Expand Down Expand Up @@ -90,8 +92,9 @@ class ConfigLocator
/**
* ConfigLocator constructor
*/
public function __construct($envPrefix = '')
public function __construct($envPrefix = '', $configFileVariant = '')
{
$this->configFileVariant = $configFileVariant;
$this->config = new DrushConfig();

// Add placeholders to establish priority. We add
Expand Down Expand Up @@ -301,8 +304,11 @@ public function addConfigPaths($contextName, $paths)

$candidates = [
'drush.yml',
'config/drush.yml',
];
if ($this->configFileVariant) {
$candidates[] = "drush{$this->configFileVariant}.yml";
}
$candidates = $this->expandCandidates($candidates, 'config/');
$config_files = $this->findConfigFiles($paths, $candidates);
$this->addConfigFiles($processor, $loader, $config_files);

Expand Down Expand Up @@ -490,6 +496,20 @@ public function setComposerRoot($selectedComposerRoot)
$this->composerRoot = $selectedComposerRoot;
}

/**
* Double the candidates, adding '$prefix' before each existing one.
*/
public function expandCandidates($candidates, $prefix)
{
$additional = array_map(
function ($item) use ($prefix) {
return $prefix . $item;
},
$candidates
);
return array_merge($candidates, $additional);
}

/**
* Given an array of paths, separates files and directories.
*
Expand Down
16 changes: 16 additions & 0 deletions src/Config/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Environment
protected $vendorDir;

protected $docPrefix;
protected $configFileVariant;

protected $loader;
protected $siteLoader;
Expand Down Expand Up @@ -230,6 +231,21 @@ public function userConfigPath()
return $this->homeDir() . '/.drush';
}

public function setConfigFileVariant($variant)
{
$this->configFileVariant = $variant;
}

/**
* Get the config file variant -- defined to be
* the Drush major version number. This is for
* loading drush.yml and drush9.yml, etc.
*/
public function getConfigFileVariant()
{
return $this->configFileVariant;
}

/**
* The original working directory
*
Expand Down
2 changes: 1 addition & 1 deletion src/Drush.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static function getVersion()
{
if (!static::$version) {
$drush_info = static::drushReadDrushInfo();
$instance = new Version($drush_info['drush_version'], DRUSH_BASE_PATH);
$instance = new Version($drush_info['drush_version'], dirname(__DIR__));
static::$version = $instance->getversion();
}
return static::$version;
Expand Down
2 changes: 1 addition & 1 deletion src/Preflight/Preflight.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __construct(Environment $environment, $verify = null, $configLoc
{
$this->environment = $environment;
$this->verify = $verify ?: new PreflightVerify();
$this->configLocator = $configLocator ?: new ConfigLocator('DRUSH_');
$this->configLocator = $configLocator ?: new ConfigLocator('DRUSH_', $environment->getConfigFileVariant());
$this->drupalFinder = new DrupalFinder();
$this->logger = new PreflightLog();
}
Expand Down