X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fchi-teck%2Fdrupal-code-generator%2Fsrc%2FHelper%2FInputHandler.php;h=51fb0ced2e7fb4aced7589f30f52641101baafef;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hp=b1007e42b467007e991c6e2cded16bf14f448f24;hpb=74df008bdbb3a11eeea356744f39b802369bda3c;p=yaffs-website diff --git a/vendor/chi-teck/drupal-code-generator/src/Helper/InputHandler.php b/vendor/chi-teck/drupal-code-generator/src/Helper/InputHandler.php index b1007e42b..51fb0ced2 100644 --- a/vendor/chi-teck/drupal-code-generator/src/Helper/InputHandler.php +++ b/vendor/chi-teck/drupal-code-generator/src/Helper/InputHandler.php @@ -42,16 +42,17 @@ class InputHandler extends Helper { */ public function collectVars(InputInterface $input, OutputInterface $output, array $questions, array $vars = []) { - // A user can pass answers through command line option. + // A user can pass answers through the command line option. + $answers = NULL; if ($answers_raw = $input->getOption('answers')) { $answers = json_decode($answers_raw, TRUE); if (!is_array($answers)) { throw new InvalidOptionException('Answers should be encoded in JSON format.'); } } - else { - $answers = []; - } + + /** @var \Symfony\Component\Console\Helper\QuestionHelper $question_helper */ + $question_helper = $this->getHelperSet()->get('question'); /** @var \DrupalCodeGenerator\Command\GeneratorInterface $command */ $command = $this->getHelperSet()->getCommand(); @@ -85,27 +86,28 @@ class InputHandler extends Helper { $default_value = call_user_func($default_value, $vars); } } - // Default value may have tokens. $default_value = Utils::tokenReplace($default_value, $vars); - $this->setQuestionDefault($question, $default_value); - if (array_key_exists($name, $answers)) { - $answer = $answers[$name]; - // Null stands for default value. - if ($answer === NULL) { - $answer = $default_value; + if ($answers) { + if (array_key_exists($name, $answers)) { + $answer = $answers[$name]; + // Validate provided answer. + if ($validator = $question->getValidator()) { + $validator($answer); + } + // Turn 'yes/no' string into boolean. + if ($question instanceof ConfirmationQuestion && !is_bool($answer)) { + $answer = strcasecmp($answer, 'yes') == 0; + } } - // Turn 'yes/no' string into boolean. - elseif ($question instanceof ConfirmationQuestion && !is_bool($answer)) { - $answer = strcasecmp($answer, 'yes') == 0; + else { + $answer = $default_value; } } else { $this->formatQuestionText($question); - /** @var \Symfony\Component\Console\Helper\QuestionHelper $question_helper */ - $question_helper = $this->getHelperSet()->get('question'); $answer = $question_helper->ask($input, $output, $question); }