Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / drush / drush / src / Psysh / Shell.php
diff --git a/vendor/drush/drush/src/Psysh/Shell.php b/vendor/drush/drush/src/Psysh/Shell.php
new file mode 100644 (file)
index 0000000..dad0127
--- /dev/null
@@ -0,0 +1,65 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drush\Psysh\Shell.
+ */
+
+namespace Drush\Psysh;
+
+use Psy\Shell as BaseShell;
+use Symfony\Component\Console\Input\StringInput;
+
+class Shell extends BaseShell
+{
+
+    /**
+     * Get a command (if one exists) for the current input string.
+     *
+     * @param string $input
+     *
+     * @return null|string
+     */
+    protected function getCommand($input)
+    {
+        if ($name = $this->getCommandFromInput($input)) {
+            return $this->get($name);
+        }
+    }
+
+    /**
+     * Check whether a command is set for the current input string.
+     *
+     * @param string $input
+     *
+     * @return bool True if the shell has a command for the given input.
+     */
+    protected function hasCommand($input)
+    {
+        if ($name = $this->getCommandFromInput($input)) {
+            return $this->has($name);
+        }
+
+        return false;
+    }
+
+    /**
+     * Get the command from the current input, takes aliases into account.
+     *
+     * @param string $input
+     *   The raw input
+     *
+     * @return string|NULL
+     *   The current command.
+     */
+    protected function getCommandFromInput($input)
+    {
+        // Remove the alias from the start of the string before parsing and
+        // returning the command. Essentially, when choosing a command, we're
+        // ignoring the site alias.
+        $input = preg_replace('|^\@[^\s]+|', '', $input);
+
+        $input = new StringInput($input);
+        return $input->getFirstArgument();
+    }
+}