Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console-core / src / Command / DrushCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Core\Command\Exclude\DrushCommand.
6  */
7
8 namespace Drupal\Console\Core\Command;
9
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Output\OutputInterface;
12 use Symfony\Component\Console\Input\InputArgument;
13 use Drupal\Console\Core\Utils\ConfigurationManager;
14 use Drupal\Console\Core\Utils\ChainQueue;
15
16 /**
17  * Class DrushCommand
18  *
19  * @package Drupal\Console\Core\Command
20  */
21 class DrushCommand extends Command
22 {
23     /**
24      * @var  ConfigurationManager
25      */
26     protected $configurationManager;
27
28     /**
29      * @var ChainQueue
30      */
31     protected $chainQueue;
32
33     /**
34      * DrushCommand constructor.
35      *
36      * @param ConfigurationManager $configurationManager
37      * @param ChainQueue           $chainQueue
38      */
39     public function __construct(
40         ConfigurationManager $configurationManager,
41         ChainQueue $chainQueue
42     ) {
43         $this->configurationManager = $configurationManager;
44         $this->chainQueue = $chainQueue;
45         parent::__construct();
46     }
47
48     /**
49      * {@inheritdoc}
50      */
51     protected function configure()
52     {
53         $this
54             ->setName('drush')
55             ->setDescription($this->trans('commands.drush.description'))
56             ->addArgument(
57                 'command-name',
58                 InputArgument::OPTIONAL,
59                 $this->trans('commands.drush.arguments.command-name'),
60                 null
61             );
62     }
63
64     /**
65      * {@inheritdoc}
66      */
67     protected function execute(InputInterface $input, OutputInterface $output)
68     {
69         $commandName = $input->getArgument('command-name');
70
71         $alternative = $this->configurationManager->readDrushEquivalents($commandName);
72
73         $this->getIo()->newLine();
74         $this->getIo()->info($this->trans('commands.drush.description'));
75         $this->getIo()->newLine();
76
77         if (!$alternative) {
78             $this->getIo()->error($this->trans('commands.drush.messages.not-found'));
79
80             return 1;
81         }
82
83         $tableHeader = ['drush','drupal console'];
84         if (is_array($alternative)) {
85             $this->getIo()->table(
86                 $tableHeader,
87                 $alternative
88             );
89
90             return 0;
91         }
92
93         $this->getIo()->table(
94             $tableHeader,
95             [[$commandName, $alternative]]
96         );
97
98         if ($this->getApplication()->has($alternative)) {
99             $this->chainQueue->addCommand(
100                 'help',
101                 ['command_name' => $alternative]
102             );
103
104             return 0;
105         }
106
107         return 0;
108     }
109 }