extensionManager = $extensionManager; $this->generator = $generator; $this->stringConverter = $stringConverter; parent::__construct(); } protected function configure() { $this ->setName('generate:authentication:provider') ->setDescription($this->trans('commands.generate.authentication.provider.description')) ->setHelp($this->trans('commands.generate.authentication.provider.help')) ->addOption('module', '', InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) ->addOption( 'class', '', InputOption::VALUE_OPTIONAL, $this->trans('commands.generate.authentication.provider.options.class') ) ->addOption( 'provider-id', '', InputOption::VALUE_OPTIONAL, $this->trans('commands.generate.authentication.provider.options.provider-id') ); } /** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration if (!$this->confirmGeneration($io)) { return; } $module = $input->getOption('module'); $class = $input->getOption('class'); $provider_id = $input->getOption('provider-id'); $this->generator->generate($module, $class, $provider_id); } protected function interact(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $stringUtils = $this->stringConverter; // --module option $module = $input->getOption('module'); if (!$module) { // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion $module = $this->moduleQuestion($io); $input->setOption('module', $module); } // --class option $class = $input->getOption('class'); if (!$class) { $class = $io->ask( $this->trans( 'commands.generate.authentication.provider.options.class' ), 'DefaultAuthenticationProvider', function ($value) use ($stringUtils) { if (!strlen(trim($value))) { throw new \Exception('The Class name can not be empty'); } return $stringUtils->humanToCamelCase($value); } ); $input->setOption('class', $class); } // --provider-id option $provider_id = $input->getOption('provider-id'); if (!$provider_id) { $provider_id = $io->ask( $this->trans('commands.generate.authentication.provider.options.provider-id'), $stringUtils->camelCaseToUnderscore($class), function ($value) use ($stringUtils) { if (!strlen(trim($value))) { throw new \Exception('The Class name can not be empty'); } return $stringUtils->camelCaseToUnderscore($value); } ); $input->setOption('provider-id', $provider_id); } } }