annotate vendor/chi-teck/drupal-code-generator/src/Command/Other/DcgCommand.php @ 0:c75dbcec494b

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