SiteAliasName
class SiteAliasName (View source)
Parse a string that contains a site alias name, and provide convenience methods to access the parts.
When provided by users, aliases must be in one of the following forms:
-
@sitename.env: List only sitename and environment.
-
@location.sitename.env: List only sitename and environment. Search only those paths where the name of the folder holding the alias files matches 'location'. Location terms may only be used when both the sitename and env are also provided.
-
@env: Look up a named environment in instances where the site root is known (e.g. via cwd). In this form, there is an implicit sitename 'self' which is replaced by the actual site alias name once known.
-
@sitename: Provides only the sitename; uses the 'default' environment, or 'dev' if there is no 'default' (or whatever is there if there is only one). With this form, the site alias name has no environment until the appropriate default environment is looked up. This form is checked only after
@env
returns no matches. This form can NOT be filtered with alocation.
term.
There are also two special aliases that are recognized:
-
@self: The current bootstrapped site.
-
@none: No alias ('root' and 'uri' unset).
The special alias forms have no environment component.
When provided to an API, the '@' is optional.
Note that @sitename and @env are ambiguous. Aliases in this form (that are not one of the special aliases) will first be assumed to be @env, and may be converted to @sitename later.
Note that:
- 'sitename' and 'env' MUST NOT contain a '.' (unlike previous versions of Drush).
- Users SHOULD NOT create any environments that have the same name as any site name (and visa-versa).
- All environments in one site record SHOULD be different versions of the same site (e.g. dev / test / live).
Constants
ALIAS_NAME_REGEX |
Match the parts of a regex name. |
Properties
protected | $location | ||
protected | $sitename | ||
protected | $env |
Methods
Create a new site alias name
The 'location' of an alias file is defined as being the name of the immediate parent of the alias file. e.g. the path '$HOME/.drush/sites/isp/mysite.site.yml' would have a location of 'isp' and a sitename of 'mysite'. The environments of the site are defined by the alias contents.
Creae a SiteAliasName object from an alias name string.
Convert an alias name back to a string.
Determine whether or not the provided name is an alias name.
Return the sitename portion of the alias name. By definition, every alias must have a sitename. If the site name is implicit, then 'self' is assumed.
Return the sitename portion of the alias name. By definition, every alias must have a sitename. If the site name is implicit, then 'self' is assumed.
Set the sitename portion of the alias name
In general, all aliases have a sitename. The time when one will not
is when an environment name @env
is used as a shortcut for @self.env
Return true if this alias name contains an 'env' portion.
Set the environment portion of the alias name.
Return the 'env' portion of the alias name.
Return true if this alias name contains a 'location' portion
Set the 'loation' portion of the alias name.
Return the 'location' portion of the alias name.
Return true if this alias name is the 'self' alias.
Return true if this alias name is the 'none' alias.
Convert the parts of an alias name to its various component parts.
Process an alias name provided as '@sitename'.
Determine whether the requested name is a special alias name.
Details
static SiteAliasName
parse(string $item)
Create a new site alias name
static type
locationFromPath(type $path)
The 'location' of an alias file is defined as being the name of the immediate parent of the alias file. e.g. the path '$HOME/.drush/sites/isp/mysite.site.yml' would have a location of 'isp' and a sitename of 'mysite'. The environments of the site are defined by the alias contents.
__construct(string $sitename = null, string $env = null, string $location = null)
Creae a SiteAliasName object from an alias name string.
string
__toString()
Convert an alias name back to a string.
static bool
isAliasName(string $aliasName)
Determine whether or not the provided name is an alias name.
string
sitename()
Return the sitename portion of the alias name. By definition, every alias must have a sitename. If the site name is implicit, then 'self' is assumed.
string
sitenameWithLocation()
Return the sitename portion of the alias name. By definition, every alias must have a sitename. If the site name is implicit, then 'self' is assumed.
setSitename(string $sitename)
Set the sitename portion of the alias name
bool
hasSitename()
In general, all aliases have a sitename. The time when one will not
is when an environment name @env
is used as a shortcut for @self.env
bool
hasEnv()
Return true if this alias name contains an 'env' portion.
setEnv($env)
Set the environment portion of the alias name.
string
env()
Return the 'env' portion of the alias name.
bool
hasLocation()
Return true if this alias name contains a 'location' portion
setLocation(string $location)
Set the 'loation' portion of the alias name.
location()
Return the 'location' portion of the alias name.
bool
isSelf()
Return true if this alias name is the 'self' alias.
isNone()
Return true if this alias name is the 'none' alias.
protected
doParse(string $aliasName)
Convert the parts of an alias name to its various component parts.
protected true
processSingleItem($item)
Process an alias name provided as '@sitename'.
protected bool
isSpecialAliasName(string $item)
Determine whether the requested name is a special alias name.