Yaffs site version 1.1
[yaffs-website] / vendor / drupal / console / src / Command / Generate / ModuleFileCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Command\Generate\ModuleFileCommand.
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\Core\Command\Shared\CommandTrait;
15 use Drupal\Console\Generator\ModuleFileGenerator;
16 use Drupal\Console\Command\Shared\ConfirmationTrait;
17 use Drupal\Console\Command\Shared\ModuleTrait;
18 use Drupal\Console\Extension\Manager;
19 use Drupal\Console\Core\Style\DrupalStyle;
20
21 /**
22  * Class ModuleFileCommand
23  *
24  * @package Drupal\Console\Command\Generate
25  */
26 class ModuleFileCommand extends Command
27 {
28     use CommandTrait;
29     use ConfirmationTrait;
30     use ModuleTrait;
31
32     /**
33  * @var Manager
34 */
35     protected $extensionManager;
36
37     /**
38  * @var ModuleFileGenerator
39 */
40     protected $generator;
41
42
43     /**
44      * ModuleFileCommand constructor.
45      *
46      * @param Manager             $extensionManager
47      * @param ModuleFileGenerator $generator
48      */
49     public function __construct(
50         Manager $extensionManager,
51         ModuleFileGenerator $generator
52     ) {
53         $this->extensionManager = $extensionManager;
54         $this->generator = $generator;
55         parent::__construct();
56     }
57
58     /**
59      * {@inheritdoc}
60      */
61     protected function configure()
62     {
63         $this
64             ->setName('generate:module:file')
65             ->setDescription($this->trans('commands.generate.module.file.description'))
66             ->setHelp($this->trans('commands.generate.module.file.help'))
67             ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module'));
68     }
69
70     /**
71      * {@inheritdoc}
72      */
73     protected function execute(InputInterface $input, OutputInterface $output)
74     {
75         $io = new DrupalStyle($input, $output);
76
77         // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration
78         if (!$this->confirmGeneration($io, $yes)) {
79             return 1;
80         }
81
82         $machine_name =  $input->getOption('module');
83         $file_path =  $this->extensionManager->getModule($machine_name)->getPath();
84         $generator = $this->generator;
85
86         $generator->generate(
87             $machine_name,
88             $file_path
89         );
90     }
91
92
93     /**
94      * {@inheritdoc}
95      */
96     protected function interact(InputInterface $input, OutputInterface $output)
97     {
98         $io = new DrupalStyle($input, $output);
99
100         // --module option
101         $module = $input->getOption('module');
102
103         if (!$module) {
104             // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion
105             $module = $this->moduleQuestion($io);
106         }
107
108         $input->setOption('module', $module);
109     }
110 }