class Environment (View source)

Store information about the environment

Properties

protected $homeDir
protected $originalCwd
protected $etcPrefix
protected $sharePrefix
protected $drushBasePath
protected $vendorDir
protected $docPrefix
protected $configFileVariant
protected $loader
protected $siteLoader

Methods

__construct(string $homeDir, string $cwd, string $autoloadFile)

Environment constructor

ClassLoader
loadSiteAutoloader(string $root)

Load the autoloader for the selected Drupal site

string
getUsername()

Return the name of the user running drush.

getTmp()

No description

array
exportConfigData()

Convert the environment object into an exported configuration array.

string
drushBasePath()

The base directory of the Drush application itself (where composer.json et.al. are found)

bool|string
getSiteSetAliasName()

Get the site:set alias from the current site:set file path.

string
homeDir()

User's home directory

string
userConfigPath()

The user's Drush configuration directory, ~/.drush

setConfigFileVariant($variant)

No description

getConfigFileVariant()

Get the config file variant -- defined to be the Drush major version number. This is for loading drush.yml and drush9.yml, etc.

string
cwd()

The original working directory

string
vendorPath()

Return the path to Drush's vendor directory

ClassLoader
loader()

The class loader returned when the autoload.php file is included.

setLoader(ClassLoader $loader)

Set the class loader from the autload.php file, if available.

$this
applyEnvironment()

Alter our default locations based on the value of environment variables

$this
setEtcPrefix(string $etcPrefix)

Set the directory prefix to locate the directory that Drush will use as /etc (e.g. during the functional tests)

$this
setSharePrefix(string $sharePrefix)

Set the directory prefix to locate the directory that Drush will use as /user/share (e.g. during the functional tests)

string
docsPath()

Return the directory where Drush's documentation is stored. Usually this is within the Drush application, but some Drush RPM distributions & c. for Linux platforms slice-and-dice the contents and put the docs elsewhere.

string
findDocsPath(string $drushBasePath)

Locate the Drush documentation. This is recalculated whenever the share prefix is changed.

string|boolean
findFromCandidates(array $candidates)

Check a list of directories and return the first one that exists.

static string
systemPathPrefix(string $override = '', string $defaultPrefix = '')

Return the appropriate system path prefix, unless an override is provided.

string
systemConfigPath()

Return the system configuration path (default: /etc/drush)

string
systemCommandFilePath()

Return the system shared commandfile path (default: /usr/share/drush/commands)

static boolean
isWindows($os = null)

Determine whether current OS is a Windows variant.

boolean
verifyCLI()

Verify that we are running PHP through the command line interface.

integer
calculateColumns()

Calculate the terminal width used for wrapping table output.

string|false
getSiteSetAliasFilePath(string $filename_prefix = 'drush-drupal-site-')

Returns the filename for the file that stores the DRUPAL_SITE variable.

Details

__construct(string $homeDir, string $cwd, string $autoloadFile)

Environment constructor

Parameters

string $homeDir User home directory.
string $cwd The current working directory at the time Drush was called.
string $autoloadFile Path to the autoload.php file.

ClassLoader loadSiteAutoloader(string $root)

Load the autoloader for the selected Drupal site

Parameters

string $root

Return Value

ClassLoader

protected string getUsername()

Return the name of the user running drush.

Return Value

string

protected getTmp()

array exportConfigData()

Convert the environment object into an exported configuration array.

Return Value

array Nested associative array that is overlayed on configuration.

See also

PreflightArgs::applyToConfig(), which also exports information to config.

string drushBasePath()

The base directory of the Drush application itself (where composer.json et.al. are found)

Return Value

string

bool|string getSiteSetAliasName()

Get the site:set alias from the current site:set file path.

Return Value

bool|string

string homeDir()

User's home directory

Return Value

string

string userConfigPath()

The user's Drush configuration directory, ~/.drush

Return Value

string

setConfigFileVariant($variant)

Parameters

$variant

getConfigFileVariant()

Get the config file variant -- defined to be the Drush major version number. This is for loading drush.yml and drush9.yml, etc.

string cwd()

The original working directory

Return Value

string

string vendorPath()

Return the path to Drush's vendor directory

Return Value

string

ClassLoader loader()

The class loader returned when the autoload.php file is included.

Return Value

ClassLoader

setLoader(ClassLoader $loader)

Set the class loader from the autload.php file, if available.

Parameters

ClassLoader $loader

$this applyEnvironment()

Alter our default locations based on the value of environment variables

Return Value

$this

$this setEtcPrefix(string $etcPrefix)

Set the directory prefix to locate the directory that Drush will use as /etc (e.g. during the functional tests)

Parameters

string $etcPrefix

Return Value

$this

$this setSharePrefix(string $sharePrefix)

Set the directory prefix to locate the directory that Drush will use as /user/share (e.g. during the functional tests)

Parameters

string $sharePrefix

Return Value

$this

string docsPath()

Return the directory where Drush's documentation is stored. Usually this is within the Drush application, but some Drush RPM distributions & c. for Linux platforms slice-and-dice the contents and put the docs elsewhere.

Return Value

string

protected string findDocsPath(string $drushBasePath)

Locate the Drush documentation. This is recalculated whenever the share prefix is changed.

Parameters

string $drushBasePath

Return Value

string

protected string|boolean findFromCandidates(array $candidates)

Check a list of directories and return the first one that exists.

Parameters

array $candidates

Return Value

string|boolean

static protected string systemPathPrefix(string $override = '', string $defaultPrefix = '')

Return the appropriate system path prefix, unless an override is provided.

Parameters

string $override
string $defaultPrefix

Return Value

string

string systemConfigPath()

Return the system configuration path (default: /etc/drush)

Return Value

string

string systemCommandFilePath()

Return the system shared commandfile path (default: /usr/share/drush/commands)

Return Value

string

static boolean isWindows($os = null)

Determine whether current OS is a Windows variant.

Parameters

$os

Return Value

boolean

boolean verifyCLI()

Verify that we are running PHP through the command line interface.

Return Value

boolean A boolean value that is true when PHP is being run through the command line, and false if being run through cgi or mod_php.

integer calculateColumns()

Calculate the terminal width used for wrapping table output.

Normally this is exported using tput in the drush script. If this is not present we do an additional check using stty here. On Windows in CMD and PowerShell is this exported using mode con.

Return Value

integer

protected string|false getSiteSetAliasFilePath(string $filename_prefix = 'drush-drupal-site-')

Returns the filename for the file that stores the DRUPAL_SITE variable.

Parameters

string $filename_prefix An arbitrary string to prefix the filename with.

Return Value

string|false Returns the full path to temp file if possible, or FALSE if not.