12 use Symfony\Component\Console\Input\InputInterface;
13 use Symfony\Component\Console\Output\OutputInterface;
14 use Symfony\Component\Console\Question\Question;
15 use Symfony\Component\Console\Question\QuestionFactory;
16 use Symfony\Component\Console\Helper\QuestionHelper;
26 private $questionFactory;
31 private $questionHelper;
38 QuestionFactory $questionFactory,
39 QuestionHelper $questionHelper
41 $this->questionFactory = $questionFactory;
42 $this->questionHelper = $questionHelper;
54 public function getValues(InputInterface $input, OutputInterface
$output, array $configPaths)
57 $configPathQuestion = $this->getConfigPathQuestion($configPaths);
58 $configPath = ($inputPath ===
null)
59 ? $this->questionHelper->ask($input,
$output, $configPathQuestion)
62 $this->validatePath($configPath, $configPaths);
65 $configValueQuestion = $this->getConfigValueQuestion();
66 $configValue = $inputValue ===
null 67 ? $this->questionHelper->ask($input,
$output, $configValueQuestion)
70 return [$configPath => $configValue];
79 private function getConfigPathQuestion(array $configPaths)
82 $configPathQuestion = $this->questionFactory->create([
83 'question' =>
'Please enter config path: ' 85 $configPathQuestion->setAutocompleterValues($configPaths);
86 $configPathQuestion->setValidator(
function ($configPath) use ($configPaths) {
87 $this->validatePath($configPath, $configPaths);
91 return $configPathQuestion;
99 private function getConfigValueQuestion()
102 $configValueQuestion = $this->questionFactory->create([
103 'question' =>
'Please enter value: ' 105 $configValueQuestion->setValidator(
function ($interviewer) {
106 if (empty($interviewer)) {
112 return $configValueQuestion;
123 private function validatePath($configPath, array $configPaths)
125 if (!in_array($configPath, $configPaths)) {
126 throw new LocalizedException(
127 new Phrase(
'A configuration with this path does not exist or is not sensitive')
const INPUT_ARGUMENT_PATH
__construct(QuestionFactory $questionFactory, QuestionHelper $questionHelper)
getValues(InputInterface $input, OutputInterface $output, array $configPaths)
const INPUT_ARGUMENT_VALUE