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 Config $config
protected $isLocal
protected $sources
protected $siteRoots
protected $composerRoot
protected $configFilePaths
protected $configFileVariant
protected $processedConfigPaths

Methods

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

ConfigLocator constructor

setLocal(bool $isLocal)

Put the config locator into 'local 'mode.

$this
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.

string[]
configFilePaths()

Return a list of all configuration files that were loaded.

addToSources(array $sources)

Accumulate the sources provided by the configuration loader.

Config
config()

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

$this
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.

$this
addPreflightConfigFiles($filepaths)

Add config paths defined in preflight configuration.

$this
addAliasConfig($aliasConfig)

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

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

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

$this
addDrushConfig($drushProjectDir)

Add the Drush project directory as a configuration search location.

$this
addSitewideConfig(Path $siteRoot)

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

$this
addConfigPaths(string $contextName, string[] $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.

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

Adds $configFiles config files.

string[]
identifyCandidates(string[] $paths, string[] $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.

string[]
identifyCandidatesAtPath(string $path, string[] $candidates)

Search for all matching candidate locations at a single path.

array
getSiteAliasPaths($paths, Environment $environment)

Get the site aliases according to preflight arguments and environment.

array
getCommandFilePaths($commandPaths, $root)

Get the commandfile paths according to preflight arguments.

getBuiltinCommandFilePaths()

Return all of the built-in commandfile locations

getIncludedCommandFilePaths($commandPaths)

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

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.

setComposerRoot($selectedComposerRoot)

Sets the composer root.

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.

Details

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

ConfigLocator constructor

Parameters

$envPrefix
$configFileVariant

setLocal(bool $isLocal)

Put the config locator into 'local 'mode.

Parameters

bool $isLocal

$this 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

$this

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

string[] configFilePaths()

Return a list of all configuration files that were loaded.

Return Value

string[]

protected addToSources(array $sources)

Accumulate the sources provided by the configuration loader.

Parameters

array $sources

Config config()

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

Return Value

Config

$this 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.

see Environment::exportConfigData()

Parameters

Environment $environment

Return Value

$this

$this addPreflightConfigFiles($filepaths)

Add config paths defined in preflight configuration.

Parameters

$filepaths

Return Value

$this

$this addAliasConfig($aliasConfig)

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

Parameters

$aliasConfig

Return Value

$this

$this 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

$this

$this addDrushConfig($drushProjectDir)

Add the Drush project directory as a configuration search location.

Parameters

$drushProjectDir path to the drush project directory

Return Value

$this

$this addSitewideConfig(Path $siteRoot)

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

Parameters

Path $siteRoot to the selected Drupal site

Return Value

$this

$this addConfigPaths(string $contextName, string[] $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.
string[] $paths List of paths to search for configuration.

Return Value

$this

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

Adds $configFiles config files.

Parameters

ConfigProcessor $processor
ConfigLoaderInterface $loader
array $configFiles

protected string[] identifyCandidates(string[] $paths, string[] $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

string[] $paths
string[] $candidates

Return Value

string[] paths

protected string[] identifyCandidatesAtPath(string $path, string[] $candidates)

Search for all matching candidate locations at a single path.

Candidate locations may be either directories or files.

Parameters

string $path
string[] $candidates

Return Value

string[]

array getSiteAliasPaths($paths, Environment $environment)

Get the site aliases according to preflight arguments and environment.

Parameters

$paths
Environment $environment

Return Value

array

array getCommandFilePaths($commandPaths, $root)

Get the commandfile paths according to preflight arguments.

Parameters

$commandPaths
$root

Return Value

array

protected getBuiltinCommandFilePaths()

Return all of the built-in commandfile locations

protected getIncludedCommandFilePaths($commandPaths)

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

Parameters

$commandPaths

protected 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

setComposerRoot($selectedComposerRoot)

Sets the composer root.

Parameters

$selectedComposerRoot

expandCandidates($candidates, $prefix)

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

Parameters

$candidates
$prefix

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 An array. The first row is an array of files, the second row is an array of dirs.