12 namespace Symfony\Component\Console\Question;
124 $selectedChoices = str_replace(
' ',
'', $selected);
128 if (!preg_match(
'/^[a-zA-Z0-9_-]+(?:,[a-zA-Z0-9_-]+)*$/', $selectedChoices, $matches)) {
129 throw new \InvalidArgumentException(sprintf(
$errorMessage, $selected));
131 $selectedChoices = explode(
',', $selectedChoices);
133 $selectedChoices = array($selected);
136 $multiselectChoices = array();
137 foreach ($selectedChoices as $value) {
139 foreach (
$choices as $key => $choice) {
140 if ($choice === $value) {
145 if (count($results) > 1) {
146 throw new \InvalidArgumentException(sprintf(
'The provided answer is ambiguous. Value should be one of %s.', implode(
' or ', $results)));
149 $result = array_search($value,
$choices);
152 if (
false !== $result) {
161 if (
false === $result) {
162 throw new \InvalidArgumentException(sprintf(
$errorMessage, $value));
165 $multiselectChoices[] = (string) $result;
169 return $multiselectChoices;
172 return current($multiselectChoices);