dad0127633dfaf50e2a0caedf12d2361f5ecb24c
[yaffs-website] / vendor / drush / drush / src / 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     /**
17      * Get a command (if one exists) for the current input string.
18      *
19      * @param string $input
20      *
21      * @return null|string
22      */
23     protected function getCommand($input)
24     {
25         if ($name = $this->getCommandFromInput($input)) {
26             return $this->get($name);
27         }
28     }
29
30     /**
31      * Check whether a command is set for the current input string.
32      *
33      * @param string $input
34      *
35      * @return bool True if the shell has a command for the given input.
36      */
37     protected function hasCommand($input)
38     {
39         if ($name = $this->getCommandFromInput($input)) {
40             return $this->has($name);
41         }
42
43         return false;
44     }
45
46     /**
47      * Get the command from the current input, takes aliases into account.
48      *
49      * @param string $input
50      *   The raw input
51      *
52      * @return string|NULL
53      *   The current command.
54      */
55     protected function getCommandFromInput($input)
56     {
57         // Remove the alias from the start of the string before parsing and
58         // returning the command. Essentially, when choosing a command, we're
59         // ignoring the site alias.
60         $input = preg_replace('|^\@[^\s]+|', '', $input);
61
62         $input = new StringInput($input);
63         return $input->getFirstArgument();
64     }
65 }