protected function registerVariable(OutputInterface $output, $commandString)
{
if (preg_match('/^(\\$\\{[a-zA-Z0-9-_.]+\\})=(.+)/', $commandString, $matches)) {
if (isset($matches[2]) && $matches[2][0] == '?') {
// Variable is already defined
if (isset($this->scriptVars[$matches[1]])) {
return $this->scriptVars[$matches[1]];
}
/* @var $dialog DialogHelper */
$dialog = $this->getHelper('dialog');
/**
* Check for select "?["
*/
if (isset($matches[2][1]) && $matches[2][1] == '[') {
if (preg_match('/\\[(.+)\\]/', $matches[2], $choiceMatches)) {
$choices = BinaryString::trimExplodeEmpty(',', $choiceMatches[1]);
$selectedIndex = $dialog->select($output, '<info>Please enter a value for <comment>' . $matches[1] . '</comment>:</info> ', $choices);
$this->scriptVars[$matches[1]] = $choices[$selectedIndex];
} else {
throw new RuntimeException('Invalid choices');
}
} else {
// normal input
$this->scriptVars[$matches[1]] = $dialog->askAndValidate($output, '<info>Please enter a value for <comment>' . $matches[1] . '</comment>:</info> ', function ($value) {
if ($value == '') {
throw new RuntimeException('Please enter a value');
}
return $value;
});
}
} else {
$this->scriptVars[$matches[1]] = $this->_replaceScriptVars($matches[2]);
}
}
}