Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / consolidation / site-alias / src / AliasRecord.php
similarity index 59%
rename from vendor/drush/drush/src/SiteAlias/AliasRecord.php
rename to vendor/consolidation/site-alias/src/AliasRecord.php
index 06ce29bc79b6710fa907f50e2e00cc0dd0d4dac2..3fc00d63e0a40cf114ff9bdc510d99044a6d3d48 100644 (file)
@@ -1,44 +1,17 @@
 <?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
@@ -46,13 +19,7 @@ class AliasRecord extends Config
     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 = '')
     {
@@ -64,17 +31,7 @@ class AliasRecord extends Config
     }
 
     /**
-     * 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)
     {
@@ -85,9 +42,7 @@ class AliasRecord extends Config
     }
 
     /**
-     * Return the name of this alias record.
-     *
-     * @return string
+     * @inheritdoc
      */
     public function name()
     {
@@ -95,9 +50,7 @@ class AliasRecord extends Config
     }
 
     /**
-     * Remember the name of this record
-     *
-     * @param string $name
+     * @inheritdoc
      */
     public function setName($name)
     {
@@ -105,7 +58,7 @@ class AliasRecord extends Config
     }
 
     /**
-     * Determine whether this alias has a root.
+     * @inheritdoc
      */
     public function hasRoot()
     {
@@ -113,17 +66,19 @@ class AliasRecord extends Config
     }
 
     /**
-     * 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()
     {
@@ -131,9 +86,7 @@ class AliasRecord extends Config
     }
 
     /**
-     * Record the uri
-     *
-     * @param string $uri
+     * @inheritdoc
      */
     public function setUri($uri)
     {
@@ -141,10 +94,7 @@ class AliasRecord extends Config
     }
 
     /**
-     * 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()
     {
@@ -156,7 +106,7 @@ class AliasRecord extends Config
     }
 
     /**
-     * Get the remote user
+     * @inheritdoc
      */
     public function remoteUser()
     {
@@ -164,7 +114,7 @@ class AliasRecord extends Config
     }
 
     /**
-     * Return true if this alias record has a remote user
+     * @inheritdoc
      */
     public function hasRemoteUser()
     {
@@ -172,7 +122,7 @@ class AliasRecord extends Config
     }
 
     /**
-     * Get the remote host
+     * @inheritdoc
      */
     public function remoteHost()
     {
@@ -180,28 +130,23 @@ class AliasRecord extends Config
     }
 
     /**
-     * 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()
     {
@@ -209,12 +154,11 @@ class AliasRecord extends Config
     }
 
     /**
-     * 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();
         }
 
@@ -222,8 +166,27 @@ class AliasRecord extends Config
     }
 
     /**
-     * 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()
     {