488f4033e378624e5baad735f85c6ea9002ee730
[yaffs-website] / vendor / drush / drush / src / Command / RemoteCommandProxy.php
1 <?php
2 namespace Drush\Command;
3
4 use Symfony\Component\Console\Command\Command;
5 use Symfony\Component\Console\Input\InputArgument;
6 use Symfony\Component\Console\Input\InputInterface;
7 use Symfony\Component\Console\Output\OutputInterface;
8 use Drush\Symfony\IndiscriminateInputDefinition;
9
10 use Drush\Runtime\RedispatchHook;
11
12 /**
13  * Create a placeholder proxy command to represent an unknown command.
14  * We use these only when executing remote commands that do not exist
15  * locally. We will let the remote end decide whether these will be
16  * "command not found," or some other behavior, as the remote end might
17  * have additional functionality installed.
18  *
19  * Also note that, for remote commands, we create the proxy command prior
20  * to attempting to bootstrap Drupal further, so the proxy command may
21  * be used in place of some command name that is available only for
22  * Drupal sites (e.g. pm:list and friends, etc.).
23  */
24 class RemoteCommandProxy extends Command
25 {
26     /** @var RedispatchHook */
27     protected $redispatchHook;
28
29     public function __construct($name, RedispatchHook $redispatchHook)
30     {
31         parent::__construct($name);
32         $this->redispatchHook = $redispatchHook;
33
34         // Put in a special input definition to avoid option validation errors.
35         $this->setDefinition(new IndiscriminateInputDefinition());
36
37         // Put in a placeholder array argument to avoid validation errors.
38         $this->addArgument(
39             'arguments',
40             InputArgument::IS_ARRAY,
41             'Proxy for command arguments'
42         );
43     }
44
45     protected function execute(InputInterface $input, OutputInterface $output)
46     {
47         $this->redispatchHook->redispatchIfRemote($input);
48         $name = $this->getName();
49         throw new \Exception("Command $name could not be executed remotely.");
50     }
51 }