generator = $generator; $this->extensionManager = $extensionManager; $this->validator = $validator; $this->stringConverter = $stringConverter; $this->site = $site; parent::__construct(); } /** * {@inheritdoc} */ protected function configure() { $this ->setName('generate:command') ->setDescription($this->trans('commands.generate.command.description')) ->setHelp($this->trans('commands.generate.command.help')) ->addOption( 'extension', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.extension') ) ->addOption( 'extension-type', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.extension-type') ) ->addOption( 'class', null, InputOption::VALUE_REQUIRED, $this->trans('commands.generate.command.options.class') ) ->addOption( 'name', null, InputOption::VALUE_REQUIRED, $this->trans('commands.generate.command.options.name') ) ->addOption( 'container-aware', null, InputOption::VALUE_NONE, $this->trans('commands.generate.command.options.container-aware') ) ->addOption( 'services', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, $this->trans('commands.common.options.services') ); } /** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $extension = $input->getOption('extension'); $extensionType = $input->getOption('extension-type'); $class = $input->getOption('class'); $name = $input->getOption('name'); $containerAware = $input->getOption('container-aware'); $services = $input->getOption('services'); $yes = $input->hasOption('yes')?$input->getOption('yes'):false; // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration if (!$this->confirmGeneration($io, $yes)) { return 1; } // @see use Drupal\Console\Command\Shared\ServicesTrait::buildServices $build_services = $this->buildServices($services); $this->generator->generate( $extension, $extensionType, $name, $class, $containerAware, $build_services ); $this->site->removeCachedServicesFile(); return 0; } /** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $extension = $input->getOption('extension'); if (!$extension) { $extension = $this->extensionQuestion($io, true, true); $input->setOption('extension', $extension->getName()); $input->setOption('extension-type', $extension->getType()); } $extensionType = $input->getOption('extension-type'); if (!$extensionType) { $extensionType = $this->extensionTypeQuestion($io); $input->setOption('extension-type', $extensionType); } $name = $input->getOption('name'); if (!$name) { $name = $io->ask( $this->trans('commands.generate.command.questions.name'), sprintf('%s:default', $extension->getName()) ); $input->setOption('name', $name); } $class = $input->getOption('class'); if (!$class) { $class = $io->ask( $this->trans('commands.generate.command.questions.class'), 'DefaultCommand', function ($class) { return $this->validator->validateCommandName($class); } ); $input->setOption('class', $class); } $containerAware = $input->getOption('container-aware'); if (!$containerAware) { $containerAware = $io->confirm( $this->trans('commands.generate.command.questions.container-aware'), false ); $input->setOption('container-aware', $containerAware); } if (!$containerAware) { // @see use Drupal\Console\Command\Shared\ServicesTrait::servicesQuestion $services = $this->servicesQuestion($io); $input->setOption('services', $services); } } }