Yaffs site version 1.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  *
22  * @package Drupal\Console\Core\Command\Exclude
23  */
24 class DrushCommand extends Command
25 {
26     use CommandTrait;
27
28     /**
29      * @var  ConfigurationManager
30      */
31     protected $configurationManager;
32
33     /**
34      * @var ChainQueue
35      */
36     protected $chainQueue;
37
38     /**
39      * DrushCommand constructor.
40      *
41      * @param ConfigurationManager $configurationManager
42      * @param ChainQueue           $chainQueue
43      */
44     public function __construct(
45         ConfigurationManager $configurationManager,
46         ChainQueue $chainQueue
47     ) {
48         $this->configurationManager = $configurationManager;
49         $this->chainQueue = $chainQueue;
50         parent::__construct();
51     }
52
53     /**
54      * {@inheritdoc}
55      */
56     protected function configure()
57     {
58         $this
59             ->setName('drush')
60             ->setDescription($this->trans('commands.drush.description'))
61             ->addArgument(
62                 'command-name',
63                 InputArgument::OPTIONAL,
64                 $this->trans('commands.drush.arguments.command-name'),
65                 null
66             );
67     }
68
69     /**
70      * {@inheritdoc}
71      */
72     protected function execute(InputInterface $input, OutputInterface $output)
73     {
74         $io = new DrupalStyle($input, $output);
75         $commandName = $input->getArgument('command-name');
76
77         $alternative = $this->configurationManager->readDrushEquivalents($commandName);
78
79         $io->newLine();
80         $io->info($this->trans('commands.drush.description'));
81         $io->newLine();
82
83         if (!$alternative) {
84             $io->error($this->trans('commands.drush.messages.not-found'));
85
86             return 1;
87         }
88
89         $tableHeader = ['drush','drupal console'];
90         if (is_array($alternative)) {
91             $io->table(
92                 $tableHeader,
93                 $alternative
94             );
95
96             return 0;
97         }
98
99         $io->table(
100             $tableHeader,
101             [[$commandName, $alternative]]
102         );
103
104         if ($this->getApplication()->has($alternative)) {
105             $this->chainQueue->addCommand(
106                 'help',
107                 ['command_name' => $alternative]
108             );
109
110             return 0;
111         }
112
113         return 0;
114     }
115 }