class ConfigLocator (View source)

Locate Drush configuration files and load them into the configuration instance.

This class knows how to find all of the global and site-local configuration files for Drush, as long as it is provided with the necessary base directories:

  • The user's home directory
  • The values provided for --config and --alias-path
  • The Drupal root

There are two operating modes that are supported:

  • Normal: All config locations are used.
  • Local: The global locations are omitted.

The mode is set via the setLocal() method.

Constants

ENVIRONMENT_CONTEXT

PREFLIGHT_CONTEXT

ALIAS_CONTEXT

SITE_CONTEXT

DRUPAL_CONTEXT

USER_CONTEXT

ENV_CONTEXT

DRUSH_CONTEXT

Properties

protected ConfigInterface $config
protected $isLocal
protected $sources
protected $siteRoots
protected $composerRoot
protected $configFilePaths
protected $configFileVariant
protected $processedConfigPaths

Methods

__construct($envPrefix = '', $configFileVariant = '')

ConfigLocator constructor

void
setLocal(bool $isLocal)

Put the config locator into 'local 'mode.

collectSources(bool $collect = true)

Keep track of the source that every config item originally came from.

array
sources()

Return all of the sources for every configuration item. The key is the address of the configuration item, and the value is the configuration file it was loaded from. Note that this method will return just an empty array unless collectSources(true) is called prior to loading configuration files.

array
configFilePaths()

Return a list of all configuration files that were loaded.

void
addToSources(array $sources)

Accumulate the sources provided by the configuration loader.

ConfigInterface
config()

Return the configuration object. Create it and load it with all identified configuration if necessary.

addEnvironment(Environment $environment)

Exports all of the information stored in the environment, and adds it to the configuration. The Environment object itself is only available during preflight; the information exported here may be obtained by commands et. al. as needed.

addPreflightConfigFiles($filepaths)

Add config paths defined in preflight configuration.

addAliasConfig($aliasConfig)

Take any configuration from the active alias record, and add it to our configuration.

addUserConfig($configPaths, $systemConfigPath, $userConfigDir)

Given the path provided via --config and the user's home directory, add all of the user configuration paths.

addDrushConfig(string $drushProjectDir)

Add the Drush project directory as a configuration search location.

addSitewideConfig($siteRoot)

Add any configuration files found around the Drupal root of the selected site.

addConfigPaths(string $contextName, array $paths)

Add any configuration file found at any of the provided paths. Both the provided location, and the directory config inside each provided location is searched for a drush.yml file.

void
addConfigFiles(ConfigProcessor $processor, ConfigLoaderInterface $loader, array $configFiles)

Adds $configFiles to the list of config files.

array
identifyCandidates(array $paths, array $candidates)

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 either directories or files.

array
identifyCandidatesAtPath(string $path, array $candidates)

Search for all matching candidate locations at a single path.

array
getSiteAliasPaths(array $paths, Environment $environment)

Get the site aliases according to preflight arguments and environment.

array
getCommandFilePaths(array $commandPaths, string $root)

Get the commandfile paths according to preflight arguments.

array
getBuiltinCommandFilePaths()

Return all of the built-in commandfile locations

array
getIncludedCommandFilePaths($commandPaths)

Return all of the commandfile locations specified via an 'include' option.

array
getSiteCommandFilePaths($root)

Return all of the commandfile paths in any '$root/drush' or 'dirname($root)/drush' directory that contains a composer.json file or a 'Commands' or 'src/Commands' directory.

void
setComposerRoot($selectedComposerRoot)

Sets the composer root.

array
expandCandidates($candidates, $prefix)

Double the candidates, adding '$prefix' before each existing one.

array
findConfigFiles(array $paths, array $candidates)

Given an array of paths, separates files and directories.

static bool
addSiteSpecificConfig(DrushConfig $config, $siteConfig)

Attempt to load site specific configuration.

Details

__construct($envPrefix = '', $configFileVariant = '')

ConfigLocator constructor

Parameters

$envPrefix
$configFileVariant

void setLocal(bool $isLocal)

Put the config locator into 'local 'mode.

Parameters

bool $isLocal

Return Value

void

ConfigLocator collectSources(bool $collect = true)

Keep track of the source that every config item originally came from.

Potentially useful in debugging. If collectSources(true) is called, then the sources will be accumulated as config files are loaded. Otherwise, this information will not be saved.

Parameters

bool $collect

Return Value

ConfigLocator

array sources()

Return all of the sources for every configuration item. The key is the address of the configuration item, and the value is the configuration file it was loaded from. Note that this method will return just an empty array unless collectSources(true) is called prior to loading configuration files.

Return Value

array

array configFilePaths()

Return a list of all configuration files that were loaded.

Return Value

array

protected void addToSources(array $sources)

Accumulate the sources provided by the configuration loader.

Parameters

array $sources

Return Value

void

ConfigInterface config()

Return the configuration object. Create it and load it with all identified configuration if necessary.

Return Value

ConfigInterface

ConfigLocator addEnvironment(Environment $environment)

Exports all of the information stored in the environment, and adds it to the configuration. The Environment object itself is only available during preflight; the information exported here may be obtained by commands et. al. as needed.

Environment::exportConfigData()

Parameters

Environment $environment

Return Value

ConfigLocator

ConfigLocator addPreflightConfigFiles($filepaths)

Add config paths defined in preflight configuration.

Parameters

$filepaths

Return Value

ConfigLocator

ConfigLocator addAliasConfig($aliasConfig)

Take any configuration from the active alias record, and add it to our configuration.

Parameters

$aliasConfig

Return Value

ConfigLocator

ConfigLocator addUserConfig($configPaths, $systemConfigPath, $userConfigDir)

Given the path provided via --config and the user's home directory, add all of the user configuration paths.

In 'local' mode, only the --config location is used.

Parameters

$configPaths
$systemConfigPath
$userConfigDir

Return Value

ConfigLocator

ConfigLocator addDrushConfig(string $drushProjectDir)

Add the Drush project directory as a configuration search location.

Parameters

string $drushProjectDir

Return Value

ConfigLocator

ConfigLocator|null addSitewideConfig($siteRoot)

Add any configuration files found around the Drupal root of the selected site.

Parameters

$siteRoot

Return Value

ConfigLocator|null

ConfigLocator addConfigPaths(string $contextName, array $paths)

Add any configuration file found at any of the provided paths. Both the provided location, and the directory config inside each provided location is searched for a drush.yml file.

Parameters

string $contextName

Which context to put all configuration files in.

array $paths

List of paths to search for configuration.

Return Value

ConfigLocator

protected void addConfigFiles(ConfigProcessor $processor, ConfigLoaderInterface $loader, array $configFiles)

Adds $configFiles to the list of config files.

Parameters

ConfigProcessor $processor
ConfigLoaderInterface $loader
array $configFiles

Return Value

void

protected array identifyCandidates(array $paths, array $candidates)

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 either directories or files.

Parameters

array $paths
array $candidates

Return Value

array paths

protected array identifyCandidatesAtPath(string $path, array $candidates)

Search for all matching candidate locations at a single path.

Candidate locations may be either directories or files.

Parameters

string $path
array $candidates

Return Value

array

array getSiteAliasPaths(array $paths, Environment $environment)

Get the site aliases according to preflight arguments and environment.

Parameters

array $paths
Environment $environment

Return Value

array

array getCommandFilePaths(array $commandPaths, string $root)

Get the commandfile paths according to preflight arguments.

Parameters

array $commandPaths
string $root

Return Value

array

protected array getBuiltinCommandFilePaths()

Return all of the built-in commandfile locations

Return Value

array

protected array getIncludedCommandFilePaths($commandPaths)

Return all of the commandfile locations specified via an 'include' option.

Parameters

$commandPaths

Return Value

array

protected array getSiteCommandFilePaths($root)

Return all of the commandfile paths in any '$root/drush' or 'dirname($root)/drush' directory that contains a composer.json file or a 'Commands' or 'src/Commands' directory.

Parameters

$root

Return Value

array

void setComposerRoot($selectedComposerRoot)

Sets the composer root.

Parameters

$selectedComposerRoot

Return Value

void

array expandCandidates($candidates, $prefix)

Double the candidates, adding '$prefix' before each existing one.

Parameters

$candidates
$prefix

Return Value

array

protected array findConfigFiles(array $paths, array $candidates)

Given an array of paths, separates files and directories.

Parameters

array $paths

An array of config paths. These may be config files or paths to dirs containing config files.

array $candidates

An array filenames that are considered config files.

Return Value

array

array whose first item is an array of files, and the second item is an array of dirs.

static bool addSiteSpecificConfig(DrushConfig $config, $siteConfig)

Attempt to load site specific configuration.

Parameters

DrushConfig $config

The config object.

$siteConfig

The site-specific config file.

Return Value

bool

the config exists and was processed.