askQuestion() public method

public askQuestion ( Symfony\Component\Console\Question\Question $question ) : string
$question Symfony\Component\Console\Question\Question
return string
 public function interact(array $configurators, $skipOptional = true, array $variables = [], array $defaults = []) : QuestionsSet
 {
     $questionCommunicator = function ($question) {
         return $this->io->askQuestion($question);
     };
     $answersSet = call_user_func($this->answerSetFactory, $variables, $defaults);
     $questions = new QuestionsSet($questionCommunicator, $answersSet, $skipOptional);
     foreach ($configurators as $configurator) {
         $configurator->interact($questions);
     }
     return $questions;
 }
 protected function confirmConfiguration()
 {
     $rows = [];
     foreach ($this->config as $section => $values) {
         foreach ($values as $name => $value) {
             $rows[] = [$name, $value];
         }
     }
     $this->io->table(['Name', 'Value'], $rows);
     return $this->io->askQuestion(new ConfirmationQuestion('Are these settings correct?'));
 }
Esempio n. 3
0
 /**
  * Ask about PHP executable file
  *
  * @param SymfonyStyle    $style
  * @param InputInterface  $input
  * @param OutputInterface $output
  * @param string          $optionName
  * @param \Closure        $validator
  * @return array
  * @throws LogicException
  */
 public function askPhpPath(SymfonyStyle $style, InputInterface $input, OutputInterface $output, $optionName = self::OPTION_NAME, \Closure $validator = null)
 {
     $validator = $validator ?: $this->getPhpValidator();
     $file = $input->getOption($optionName);
     if (!$file) {
         $file = $this->getSystemPhpPath();
     }
     $max = 3;
     $i = 0;
     while (!$file || !$validator($file, $output)) {
         if ($file) {
             $output->writeln('Given PHP executable file is not valid.');
         }
         $file = $style->askQuestion($this->getSimpleQuestion()->getQuestion('Please set your PHP executable file', $file));
         // @codingStandardsIgnoreStart
         if (++$i > $max) {
             throw new LogicException('Path to PHP executable file is not set.');
         }
         // @codingStandardsIgnoreEnd
     }
     return $file;
 }
Esempio n. 4
0
 /**
  * Gather changes for the new version.
  *
  * @return array
  */
 protected function gatherChanges()
 {
     $converter = new CommonMarkConverter();
     $changes = [];
     foreach ($this->changelog->getSections() as $section) {
         $sectionChanges = [];
         // Prepare question
         $question = new Question('Add something to "' . ucfirst($section) . '"');
         $question->setValidator(function ($value) {
             return $value ?: 'NOPE';
         });
         // Gather changes from user
         while ($change = $this->output->askQuestion($question)) {
             if ($change === 'NOPE') {
                 break;
             }
             $sectionChanges[] = $converter->convertToHtml($change);
         }
         if ($sectionChanges) {
             $changes[$section] = $sectionChanges;
         }
     }
     return $changes;
 }
Esempio n. 5
0
 /**
  * Give the user a single choice from an array of answers.
  *
  * @param  string $question
  * @param  array $choices
  * @param  string $default
  * @param  mixed $attempts
  * @param  bool $multiple
  * @return bool
  */
 public function choice($question, array $choices, $default = null, $attempts = null, $multiple = null)
 {
     $question = new ChoiceQuestion($question, $choices, $default);
     $question->setMaxAttempts($attempts)->setMultiselect($multiple);
     return $this->output->askQuestion($question);
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new SymfonyStyle($input, $output);
     $input->isInteractive() ? $io->title('Symfony Password Encoder Utility') : $io->newLine();
     $password = $input->getArgument('password');
     $userClass = $input->getArgument('user-class');
     $emptySalt = $input->getOption('empty-salt');
     $encoder = $this->getContainer()->get('security.encoder_factory')->getEncoder($userClass);
     $bcryptWithoutEmptySalt = !$emptySalt && $encoder instanceof BCryptPasswordEncoder;
     if ($bcryptWithoutEmptySalt) {
         $emptySalt = true;
     }
     if (!$password) {
         if (!$input->isInteractive()) {
             $io->error('The password must not be empty.');
             return 1;
         }
         $passwordQuestion = $this->createPasswordQuestion();
         $password = $io->askQuestion($passwordQuestion);
     }
     $salt = null;
     if ($input->isInteractive() && !$emptySalt) {
         $emptySalt = true;
         $io->note('The command will take care of generating a salt for you. Be aware that some encoders advise to let them generate their own salt. If you\'re using one of those encoders, please answer \'no\' to the question below. ' . PHP_EOL . 'Provide the \'empty-salt\' option in order to let the encoder handle the generation itself.');
         if ($io->confirm('Confirm salt generation ?')) {
             $salt = $this->generateSalt();
             $emptySalt = false;
         }
     } elseif (!$emptySalt) {
         $salt = $this->generateSalt();
     }
     $encodedPassword = $encoder->encodePassword($password, $salt);
     $rows = array(array('Encoder used', get_class($encoder)), array('Encoded password', $encodedPassword));
     if (!$emptySalt) {
         $rows[] = array('Generated salt', $salt);
     }
     $io->table(array('Key', 'Value'), $rows);
     if (!$emptySalt) {
         $io->note(sprintf('Make sure that your salt storage field fits the salt length: %s chars', strlen($salt)));
     } elseif ($bcryptWithoutEmptySalt) {
         $io->note('Bcrypt encoder used: the encoder generated its own built-in salt.');
     }
     $io->success('Password encoding succeeded');
 }