ConfigLocator
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 DrushConfig | $config | ||
protected bool | $isLocal | ||
protected | $sources | ||
protected | $siteRoots | ||
protected | $composerRoot | ||
protected | $configFilePaths | ||
protected | $configFileVariant | ||
protected | $processedConfigPaths |
Methods
ConfigLocator constructor
Put the config locator into 'local 'mode.
Keep track of the source that every config item originally came from.
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 a list of all configuration files that were loaded.
Accumulate the sources provided by the configuration loader.
Return the configuration object. Create it and load it with all identified configuration if necessary.
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.
Add config paths defined in preflight configuration.
Take any configuration from the active alias record, and add it to our configuration.
Given the path provided via --config and the user's home directory, add all of the user configuration paths.
Add the Drush project directory as a configuration search location.
Add any configuration files found around the Drupal root of the selected site.
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.
Adds $configFiles to the list of config files.
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.
Search for all matching candidate locations at a single path.
Get the site aliases according to preflight arguments and environment.
Get the commandfile paths according to preflight arguments.
Return all of the built-in commandfile locations
Return all of the commandfile locations specified via an 'include' option.
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.
Sets the composer root.
Double the candidates, adding '$prefix' before each existing one.
Given an array of paths, separates files and directories.
Attempt to load site specific configuration.
Details
__construct($envPrefix = '', $configFileVariant = '')
ConfigLocator constructor
void
setLocal(bool $isLocal)
Put the config locator into 'local 'mode.
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.
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.
protected void
addToSources(array $sources)
Accumulate the sources provided by the configuration loader.
DrushConfig
config()
Return the configuration object. Create it and load it with all identified configuration if necessary.
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()
ConfigLocator
addPreflightConfigFiles(array $filepaths)
Add config paths defined in preflight configuration.
ConfigLocator
addAliasConfig($aliasConfig)
Take any configuration from the active alias record, and add it to our configuration.
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.
ConfigLocator
addDrushConfig(string $drushProjectDir)
Add the Drush project directory as a configuration search location.
ConfigLocator|null
addSitewideConfig(string $siteRoot)
Add any configuration files found around the Drupal root of the selected site.
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.
protected void
addConfigFiles(ConfigProcessor $processor, ConfigLoader $loader, array $configFiles)
Adds $configFiles to the list of config files.
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.
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.
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.
protected array
getBuiltinCommandFilePaths()
Return all of the built-in commandfile locations
protected array
getIncludedCommandFilePaths($commandPaths)
Return all of the commandfile locations specified via an 'include' option.
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.
void
setComposerRoot($selectedComposerRoot)
Sets the composer root.
array
expandCandidates($candidates, $prefix)
Double the candidates, adding '$prefix' before each existing one.
protected 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.