class SiteAliasFileLoader (View source)

Discover alias files:

  • sitename.site.yml: contains multiple aliases, one for each of the environments of 'sitename'.

Properties

protected SiteAliasFileDiscovery $discovery
protected array $referenceData
protected array $loader
protected string $root

Methods

__construct(SiteAliasFileDiscovery|null $discovery = null)

SiteAliasFileLoader constructor

setReferenceData($data)

Allow configuration data to be used in replacements in the alias file.

setRoot($root)

Allow 'self.site.yml' to be applied to any alias record found.

$this
addSearchLocation(string $path)

Add a search location to our discovery object.

discovery()

Return our discovery object.

SiteAlias|false
load(SiteAliasName $aliasName)

Load the file containing the specified alias name.

loadDefaultEnvFromSitename($sitename)

Given only a site name, load the default environment from it.

loadAll()

Return a list of all site aliases loadable from any findable path.

string[]
listAll(string $location = '')

Return a list of all available alias files. Does not include legacy files.

SiteAlias[]|false
loadMultiple(string $sitename, $location = null)

Given an alias name that might represent multiple sites, return a list of all matching alias records. If nothing was found, or the name represents a single site + env, then we take no action and return false.

loadLocation(string $location)

Given a location, return all alias files located there.

createSiteAliassFromSiteData($sitename, array $siteData, $location = '')

No description

isValidEnvName(string $envName)

isValidEnvName determines if a given entry should be skipped or not (e.g. the "common" entry).

storeSiteAliasInResut($result, SiteAlias $aliasRecord)

No description

SiteAlias|false
loadSingleAliasFile(SiteAliasName $aliasName)

If the alias name is '@sitename', or if it is '@sitename.env', then look for a sitename.site.yml file that contains it. We also handle '@location.sitename.env' here as well.

loadSingleSiteAliasFileAtPath(string $path)

Given only the path to an alias file site.alias.yml, return all of the alias records for every environment stored in that file.

siteNameFromPath(string $path)

Given the path to a single site alias file site.alias.yml, return the site part.

string
basenameWithoutExtension(string $path, string $extension)

Chop off the aliases.yml or alias.yml part of a path. This works just like basename, except it will throw if the provided path does not end in the specified extension.

SiteAlias|false
loadSingleAliasFileWithNameAtPath(SiteAliasName $aliasName, string $path)

Given an alias name and a path, load the data from the path and process it as needed to generate the alias record.

array|bool
loadSiteDataFromPath(string $path)

Load the yml from the given path

array
findSelfSiteAliases($site_aliases, $path)

Given an array of site aliases, find the first one that is local (has no 'host' item) and also contains a 'self.site.yml' file.

loadSelfSiteData($root)

Check to see if there is a 'drush/sites/self.site.yml' file at the provided root, or one directory up from there.

array
loadData(string $path)

Load the contents of the specified file.

getLoader($extension)

No description

addLoader($extension, DataFileLoaderInterface $loader)

No description

SiteAlias|false
fetchSiteAliasFromSiteAliasData(SiteAliasName $aliasName, ConfigProcessor $processor, array $data)

Given an array containing site alias data, return an alias record containing the data for the requested record. If there is a 'common' section, then merge that in as well.

array|false
getRequestedEnvData(array $data, string $env)

getRequestedEnvData fetches the data for the specified environment from the provided site record data.

bool
siteEnvExists(array $data, string $env)

Determine whether there is a valid-looking environment '$env' in the provided site alias data.

array
adjustIfSingleAlias(array $data)

Adjust the alias data for a single-site alias. Usually, a .yml alias file will contain multiple entries, one for each of the environments of an alias. If there are no environments

bool
detectSingleAlias(array $data)

A single-environment alias looks something like this:

string
getEnvironmentName(SiteAliasName $aliasName, array $data)

Return the name of the environment requested.

string
getDefaultEnvironmentName(array $data)

Given a data array containing site alias environments, determine which envirionmnet should be used as the default environment.

Details

__construct(SiteAliasFileDiscovery|null $discovery = null)

SiteAliasFileLoader constructor

Parameters

SiteAliasFileDiscovery|null $discovery

setReferenceData($data)

Allow configuration data to be used in replacements in the alias file.

Parameters

$data

setRoot($root)

Allow 'self.site.yml' to be applied to any alias record found.

Parameters

$root

$this addSearchLocation(string $path)

Add a search location to our discovery object.

Parameters

string $path

Return Value

$this

SiteAliasFileDiscovery discovery()

Return our discovery object.

Return Value

SiteAliasFileDiscovery

SiteAlias|false load(SiteAliasName $aliasName)

Load the file containing the specified alias name.

Parameters

SiteAliasName $aliasName

Return Value

SiteAlias|false

protected loadDefaultEnvFromSitename($sitename)

Given only a site name, load the default environment from it.

Parameters

$sitename

SiteAlias[] loadAll()

Return a list of all site aliases loadable from any findable path.

Return Value

SiteAlias[]

string[] listAll(string $location = '')

Return a list of all available alias files. Does not include legacy files.

Parameters

string $location

Only consider alias files in the specified location.

Return Value

string[]

SiteAlias[]|false loadMultiple(string $sitename, $location = null)

Given an alias name that might represent multiple sites, return a list of all matching alias records. If nothing was found, or the name represents a single site + env, then we take no action and return false.

Parameters

string $sitename

The site name to return all environments for.

$location

Return Value

SiteAlias[]|false

SiteAlias[] loadLocation(string $location)

Given a location, return all alias files located there.

Parameters

string $location

The location to filter.

Return Value

SiteAlias[]

protected SiteAlias[] createSiteAliassFromSiteData($sitename, array $siteData, $location = '')

No description

Parameters

$sitename
array $siteData

list of sites with its respective data

$location

Return Value

SiteAlias[]

protected isValidEnvName(string $envName)

isValidEnvName determines if a given entry should be skipped or not (e.g. the "common" entry).

Parameters

string $envName

The environment name to test

protected storeSiteAliasInResut($result, SiteAlias $aliasRecord)

No description

Parameters

$result
SiteAlias $aliasRecord

protected SiteAlias|false loadSingleAliasFile(SiteAliasName $aliasName)

If the alias name is '@sitename', or if it is '@sitename.env', then look for a sitename.site.yml file that contains it. We also handle '@location.sitename.env' here as well.

Parameters

SiteAliasName $aliasName

Return Value

SiteAlias|false

protected SiteAlias[] loadSingleSiteAliasFileAtPath(string $path)

Given only the path to an alias file site.alias.yml, return all of the alias records for every environment stored in that file.

Parameters

string $path

Return Value

SiteAlias[]

protected siteNameFromPath(string $path)

Given the path to a single site alias file site.alias.yml, return the site part.

Parameters

string $path

protected string basenameWithoutExtension(string $path, string $extension)

Chop off the aliases.yml or alias.yml part of a path. This works just like basename, except it will throw if the provided path does not end in the specified extension.

Parameters

string $path
string $extension

Return Value

string

Exceptions

Exception

protected SiteAlias|false loadSingleAliasFileWithNameAtPath(SiteAliasName $aliasName, string $path)

Given an alias name and a path, load the data from the path and process it as needed to generate the alias record.

Parameters

SiteAliasName $aliasName
string $path

Return Value

SiteAlias|false

protected array|bool loadSiteDataFromPath(string $path)

Load the yml from the given path

Parameters

string $path

Return Value

array|bool

protected array findSelfSiteAliases($site_aliases, $path)

Given an array of site aliases, find the first one that is local (has no 'host' item) and also contains a 'self.site.yml' file.

Parameters

$site_aliases
$path

Return Value

array

protected loadSelfSiteData($root)

Check to see if there is a 'drush/sites/self.site.yml' file at the provided root, or one directory up from there.

Parameters

$root

protected array loadData(string $path)

Load the contents of the specified file.

Parameters

string $path

Path to file to load

Return Value

array

DataFileLoaderInterface getLoader($extension)

No description

Parameters

$extension

Return Value

DataFileLoaderInterface

addLoader($extension, DataFileLoaderInterface $loader)

No description

Parameters

$extension
DataFileLoaderInterface $loader

protected SiteAlias|false fetchSiteAliasFromSiteAliasData(SiteAliasName $aliasName, ConfigProcessor $processor, array $data)

Given an array containing site alias data, return an alias record containing the data for the requested record. If there is a 'common' section, then merge that in as well.

Parameters

SiteAliasName $aliasName

the alias we are loading

ConfigProcessor $processor
array $data

Return Value

SiteAlias|false

protected array|false getRequestedEnvData(array $data, string $env)

getRequestedEnvData fetches the data for the specified environment from the provided site record data.

Parameters

array $data

The site alias data

string $env

The name of the environment desired

Return Value

array|false

protected bool siteEnvExists(array $data, string $env)

Determine whether there is a valid-looking environment '$env' in the provided site alias data.

Parameters

array $data
string $env

Return Value

bool

protected array adjustIfSingleAlias(array $data)

Adjust the alias data for a single-site alias. Usually, a .yml alias file will contain multiple entries, one for each of the environments of an alias. If there are no environments

Parameters

array $data

Return Value

array

protected bool detectSingleAlias(array $data)

A single-environment alias looks something like this:


root: /path/to/drupal uri: https://mysite.org

A multiple-environment alias looks something like this:


default: dev dev: root: /path/to/dev uri: https://dev.mysite.org stage: root: /path/to/stage uri: https://stage.mysite.org

The differentiator between these two is that the multi-environment alias always has top-level elements that are associative arrays, and the single-environment alias never does.

Parameters

array $data

Return Value

bool

protected string getEnvironmentName(SiteAliasName $aliasName, array $data)

Return the name of the environment requested.

Parameters

SiteAliasName $aliasName

the alias we are loading

array $data

Return Value

string

protected string getDefaultEnvironmentName(array $data)

Given a data array containing site alias environments, determine which envirionmnet should be used as the default environment.

Parameters

array $data

Return Value

string