class Environment (View source)

Store information about the environment

Properties

protected string $homeDir
protected string $originalCwd
protected string $etcPrefix
protected string $sharePrefix
protected string $drushBasePath
protected string $vendorDir
protected string|null $docPrefix
protected string $configFileVariant
protected ClassLoader $loader
protected ClassLoader|null $siteLoader

Methods

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

Environment constructor

string
getUsername()

Return the name of the user running drush.

string
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

void
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 drush10.yml, etc.

string
cwd()

The original working directory

string
vendorPath()

Return the path to Drush's vendor directory

ClassLoader|null
loader()

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

void
setLoader(ClassLoader $loader)

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

applyEnvironment()

Alter our default locations based on the value of environment variables.

setEtcPrefix(mixed $etcPrefix)

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

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|null
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|bool
findDocsPath(string $drushBasePath)

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

bool|string
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 bool
isWindows($os = null)

Determine whether current OS is a Windows variant.

bool
verifyCLI()

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

int
calculateColumns()

Get terminal width.

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.

protected string getUsername()

Return the name of the user running drush.

Return Value

string

protected string getTmp()

No description

Return Value

string

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

void setConfigFileVariant($variant)

No description

Parameters

$variant

Return Value

void

getConfigFileVariant()

Get the config file variant -- defined to be the Drush major version number. This is for loading drush.yml and drush10.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|null loader()

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

Return Value

ClassLoader|null

void setLoader(ClassLoader $loader)

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

Parameters

ClassLoader $loader

Return Value

void

Environment applyEnvironment()

Alter our default locations based on the value of environment variables.

Return Value

Environment

Environment setEtcPrefix(mixed $etcPrefix)

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

Parameters

mixed $etcPrefix

Return Value

Environment

Environment 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

Environment

string|null 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|null

protected string|bool findDocsPath(string $drushBasePath)

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

Parameters

string $drushBasePath

Return Value

string|bool

protected bool|string findFromCandidates(array $candidates)

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

Parameters

array $candidates

Return Value

bool|string

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 bool isWindows($os = null)

Determine whether current OS is a Windows variant.

Parameters

$os

Return Value

bool

bool verifyCLI()

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

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.

Return Value

bool

int calculateColumns()

Get terminal width.

Return Value

int

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.