f06f8c7e8d0ba77dc96237c4431c60926777e4de
[yaffs-website] / vendor / chi-teck / drupal-code-generator / src / Command / Other / DcgCommand.php
1 <?php
2
3 namespace DrupalCodeGenerator\Command\Other;
4
5 use DrupalCodeGenerator\Command\BaseGenerator;
6 use DrupalCodeGenerator\Utils;
7 use Symfony\Component\Console\Input\InputInterface;
8 use Symfony\Component\Console\Output\OutputInterface;
9 use Symfony\Component\Console\Question\Question;
10
11 /**
12  * Implements other:dcg-command command.
13  */
14 class DcgCommand extends BaseGenerator {
15
16   protected $name = 'other:dcg-command';
17   protected $description = 'Generates DCG command';
18   protected $alias = 'dcg-command';
19   protected $label = 'DCG command';
20
21   /**
22    * {@inheritdoc}
23    */
24   protected function configure() {
25     $this->destination = Utils::getHomeDirectory() . '/.dcg/Command';
26     parent::configure();
27   }
28
29   /**
30    * {@inheritdoc}
31    */
32   protected function interact(InputInterface $input, OutputInterface $output) {
33
34     $questions = [
35       'name' => new Question('Command name', 'custom:example'),
36       'description' => new Question('Command description', 'Some description'),
37       'alias' => new Question('Command alias', 'example'),
38     ];
39
40     $vars = &$this->collectVars($input, $output, $questions);
41
42     $sub_names = explode(':', $vars['name']);
43     $last_sub_name = array_pop($sub_names);
44     $vars['class'] = Utils::camelize($last_sub_name);
45     $vars['namespace'] = 'DrupalCodeGenerator\Command';
46     $vars['template_name'] = $last_sub_name . '.twig';
47
48     $vars['path'] = '';
49     $file_path = '';
50     if ($sub_names) {
51       $vars['namespace'] .= '\\' . implode('\\', $sub_names);
52       $file_path = implode(DIRECTORY_SEPARATOR, $sub_names);
53       $vars['path'] = '/' . $file_path;
54     }
55
56     $this->addFile()
57       ->path($file_path . '/{class}.php')
58       ->template('other/dcg-command.twig');
59
60     $this->addFile()
61       ->path($file_path . '/{template_name}')
62       ->template('other/dcg-command-template.twig');
63   }
64
65 }