Yaffs site version 1.1
[yaffs-website] / vendor / drupal / console / src / Command / Generate / HelpCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Command\Generate\HelpCommand.
6  */
7
8 namespace Drupal\Console\Command\Generate;
9
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Input\InputOption;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Symfony\Component\Console\Command\Command;
14 use Drupal\Console\Generator\HelpGenerator;
15 use Drupal\Console\Command\Shared\ModuleTrait;
16 use Drupal\Console\Command\Shared\ConfirmationTrait;
17 use Drupal\Console\Core\Command\Shared\CommandTrait;
18 use Drupal\Console\Extension\Manager;
19 use Drupal\Console\Core\Style\DrupalStyle;
20 use Drupal\Console\Utils\Site;
21 use Drupal\Console\Core\Utils\ChainQueue;
22
23 class HelpCommand extends Command
24 {
25     use CommandTrait;
26     use ModuleTrait;
27     use ConfirmationTrait;
28
29     /**
30  * @var HelpGenerator
31 */
32     protected $generator;
33
34     /**
35      * @var Site
36      */
37     protected $site;
38
39     /**
40  * @var Manager
41 */
42     protected $extensionManager;
43
44     /**
45      * @var ChainQueue
46      */
47     protected $chainQueue;
48
49
50     /**
51      * HelpCommand constructor.
52      *
53      * @param HelpGenerator $generator
54      * @param Site          $site
55      * @param Manager       $extensionManager
56      * @param ChainQueue    $chainQueue
57      */
58     public function __construct(
59         HelpGenerator $generator,
60         Site $site,
61         Manager $extensionManager,
62         ChainQueue $chainQueue
63     ) {
64         $this->generator = $generator;
65         $this->site = $site;
66         $this->extensionManager = $extensionManager;
67         $this->chainQueue = $chainQueue;
68         parent::__construct();
69     }
70
71     protected function configure()
72     {
73         $this
74             ->setName('generate:help')
75             ->setDescription($this->trans('commands.generate.help.description'))
76             ->setHelp($this->trans('commands.generate.help.help'))
77             ->addOption(
78                 'module',
79                 null,
80                 InputOption::VALUE_REQUIRED,
81                 $this->trans('commands.common.options.module')
82             )
83             ->addOption(
84                 'description',
85                 null,
86                 InputOption::VALUE_OPTIONAL,
87                 $this->trans('commands.generate.module.options.description')
88             );
89     }
90
91     /**
92      * {@inheritdoc}
93      */
94     protected function execute(InputInterface $input, OutputInterface $output)
95     {
96         $io = new DrupalStyle($input, $output);
97
98         // @see use Drupal\Console\Command\ConfirmationTrait::confirmGeneration
99         if (!$this->confirmGeneration($io)) {
100             return 1;
101         }
102
103         $module = $input->getOption('module');
104
105         if ($this->extensionManager->validateModuleFunctionExist($module, $module . '_help')) {
106             throw new \Exception(
107                 sprintf(
108                     $this->trans('commands.generate.help.messages.help-already-implemented'),
109                     $module
110                 )
111             );
112         }
113
114         $description = $input->getOption('description');
115
116         $this
117             ->generator
118             ->generate($module, $description);
119
120         $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']);
121
122         return 0;
123     }
124
125     protected function interact(InputInterface $input, OutputInterface $output)
126     {
127         $io = new DrupalStyle($input, $output);
128
129         $this->site->loadLegacyFile('/core/includes/update.inc');
130         $this->site->loadLegacyFile('/core/includes/schema.inc');
131
132         $module = $input->getOption('module');
133         if (!$module) {
134             // @see Drupal\Console\Command\ModuleTrait::moduleQuestion
135             $module = $this->moduleQuestion($io);
136             $input->setOption('module', $module);
137         }
138
139         $description = $input->getOption('description');
140         if (!$description) {
141             $description = $io->ask(
142                 $this->trans('commands.generate.module.questions.description'),
143                 'My Awesome Module'
144             );
145         }
146         $input->setOption('description', $description);
147     }
148 }