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