7e065af8f32e72beba4d7459db700015e945c58d
[yaffs-website] / vendor / drush / drush / lib / Drush / Psysh / Shell.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drush\Psysh\Shell.
6  */
7
8 namespace Drush\Psysh;
9
10 use Psy\Shell as BaseShell;
11 use Symfony\Component\Console\Input\StringInput;
12
13 class Shell extends BaseShell {
14
15   /**
16    * Get a command (if one exists) for the current input string.
17    *
18    * @param string $input
19    *
20    * @return null|Command
21    */
22   protected function getCommand($input) {
23     if ($name = $this->getCommandFromInput($input)) {
24       return $this->get($name);
25     }
26   }
27
28   /**
29    * Check whether a command is set for the current input string.
30    *
31    * @param string $input
32    *
33    * @return bool True if the shell has a command for the given input.
34    */
35   protected function hasCommand($input) {
36     if ($name = $this->getCommandFromInput($input)) {
37       return $this->has($name);
38     }
39
40     return false;
41   }
42
43   /**
44    * Get the command from the current input, takes aliases into account.
45    *
46    * @param string $input
47    *   The raw input
48    *
49    * @return string|NULL
50    *   The current command.
51    */
52   protected function getCommandFromInput($input) {
53     // Remove the alias from the start of the string before parsing and
54     // returning the command. Essentially, when choosing a command, we're
55     // ignoring the site alias.
56     $input = preg_replace('|^\@[^\s]+|', '', $input);
57
58     $input = new StringInput($input);
59     return $input->getFirstArgument();
60   }
61
62 }