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