<?php
-namespace Drush\SiteAlias;
+namespace Consolidation\SiteAlias;
use Consolidation\Config\Config;
use Consolidation\Config\ConfigInterface;
use Consolidation\Config\Util\ArrayUtil;
-use Drush\Utils\FsUtils;
+use Consolidation\SiteAlias\Util\FsUtils;
/**
* An alias record is a configuration record containing well-known items.
*
- * NOTE: AliasRecord is implemented as a Config subclass; however, it
- * should not be used as a config. (A better implementation would be
- * "hasa" config, but that is less convenient, as we want all of the
- * same capabilities as a config object).
- *
- * If using an alias record as config is desired, use the 'exportConfig()'
- * method.
- *
- * Example remote alias:
- *
- * ---
- * host: www.myisp.org
- * user: www-data
- * root: /path/to/drupal
- * uri: mysite.org
- *
- * Example local alias with global and command-specific options:
- *
- * ---
- * root: /path/to/drupal
- * uri: mysite.org
- * options:
- * no-interaction: true
- * command:
- * user:
- * login:
- * options:
- * name: superuser
+ * @see AliasRecordInterface for documentation
*/
-class AliasRecord extends Config
+class AliasRecord extends Config implements AliasRecordInterface
{
/**
* @var string
protected $name;
/**
- * AliasRecord constructor
- *
- * @param array|null $data Initial data for alias record
- * @param string $name Alias name or site specification for this alias record
- * @param string $env Environment for this alias record. Will be appended to
- * the alias name, separated by a "." if provided.
- * @return type
+ * @inheritdoc
*/
public function __construct(array $data = null, $name = '', $env = '')
{
}
/**
- * Get a value from the provided config option. Values stored in
- * this alias record will override the configuration values, if present.
- *
- * If multiple alias records need to be chained together in a more
- * complex priority arrangement, @see \Consolidation\Config\Config\ConfigOverlay.
- *
- * @param ConfigInterface $config The configuration object to pull fallback data from
- * @param string $key The data item to fetch
- * @param mixed $default The default value to return if there is no match
- *
- * @return string
+ * @inheritdoc
*/
public function getConfig(ConfigInterface $config, $key, $default = null)
{
}
/**
- * Return the name of this alias record.
- *
- * @return string
+ * @inheritdoc
*/
public function name()
{
}
/**
- * Remember the name of this record
- *
- * @param string $name
+ * @inheritdoc
*/
public function setName($name)
{
}
/**
- * Determine whether this alias has a root.
+ * @inheritdoc
*/
public function hasRoot()
{
}
/**
- * Get the root
+ * @inheritdoc
*/
public function root()
{
- $root = FsUtils::realpath($this->get('root'));
-
+ $root = $this->get('root');
+ if ($this->isLocal()) {
+ return FsUtils::realpath($root);
+ }
return $root;
}
/**
- * Get the uri
+ * @inheritdoc
*/
public function uri()
{
}
/**
- * Record the uri
- *
- * @param string $uri
+ * @inheritdoc
*/
public function setUri($uri)
{
}
/**
- * Return user@host, or just host if there is no user. Returns
- * an empty string if there is no host.
- *
- * @return string
+ * @inheritdoc
*/
public function remoteHostWithUser()
{
}
/**
- * Get the remote user
+ * @inheritdoc
*/
public function remoteUser()
{
}
/**
- * Return true if this alias record has a remote user
+ * @inheritdoc
*/
public function hasRemoteUser()
{
}
/**
- * Get the remote host
+ * @inheritdoc
*/
public function remoteHost()
{
}
/**
- * Return true if this alias record has a remote host that is not
- * the local host
+ * @inheritdoc
*/
public function isRemote()
{
- return !$this->isLocal();
+ return $this->has('host');
}
/**
- * Return true if this alias record is for the local system
+ * @inheritdoc
*/
public function isLocal()
{
- if ($host = $this->remoteHost()) {
- return $host == 'localhost' || $host == '127.0.0.1';
- }
- return true;
+ return !$this->isRemote();
}
/**
- * Determine whether this alias does not represent any site. An
- * alias record must either be remote or have a root.
+ * @inheritdoc
*/
public function isNone()
{
}
/**
- * Return the 'root' element of this alias if this alias record
- * is local.
+ * @inheritdoc
*/
public function localRoot()
{
- if (!$this->isRemote()) {
+ if ($this->isLocal() && $this->hasRoot()) {
return $this->root();
}
}
/**
- * Export the configuration values in this alias record, and reconfigure
- * them so that the layout matches that of the global configuration object.
+ * os returns the OS that this alias record points to. For local alias
+ * records, PHP_OS will be returned. For remote alias records, the
+ * value from the `os` element will be returned. If there is no `os`
+ * element, then the default assumption is that the remote system is Linux.
+ *
+ * @return string
+ * Linux
+ * WIN* (e.g. WINNT)
+ * CYGWIN
+ * MINGW* (e.g. MINGW32)
+ */
+ public function os()
+ {
+ if ($this->isLocal()) {
+ return PHP_OS;
+ }
+ return $this->get('os', 'Linux');
+ }
+
+ /**
+ * @inheritdoc
*/
public function exportConfig()
{