comparison vendor/symfony/console/Question/ChoiceQuestion.php @ 12:7a779792577d

Update Drupal core to v8.4.5 (via Composer)
author Chris Cannam
date Fri, 23 Feb 2018 15:52:07 +0000
parents 4c8ae668cc8c
children 1fec387a4317
comparison
equal deleted inserted replaced
11:bfffd8d7479a 12:7a779792577d
32 * @param array $choices The list of available choices 32 * @param array $choices The list of available choices
33 * @param mixed $default The default answer to return 33 * @param mixed $default The default answer to return
34 */ 34 */
35 public function __construct($question, array $choices, $default = null) 35 public function __construct($question, array $choices, $default = null)
36 { 36 {
37 if (!$choices) {
38 throw new \LogicException('Choice question must have at least 1 choice available.');
39 }
40
37 parent::__construct($question, $default); 41 parent::__construct($question, $default);
38 42
39 $this->choices = $choices; 43 $this->choices = $choices;
40 $this->setValidator($this->getDefaultValidator()); 44 $this->setValidator($this->getDefaultValidator());
41 $this->setAutocompleterValues($choices); 45 $this->setAutocompleterValues($choices);
135 // Collapse all spaces. 139 // Collapse all spaces.
136 $selectedChoices = str_replace(' ', '', $selected); 140 $selectedChoices = str_replace(' ', '', $selected);
137 141
138 if ($multiselect) { 142 if ($multiselect) {
139 // Check for a separated comma values 143 // Check for a separated comma values
140 if (!preg_match('/^[a-zA-Z0-9_-]+(?:,[a-zA-Z0-9_-]+)*$/', $selectedChoices, $matches)) { 144 if (!preg_match('/^[^,]+(?:,[^,]+)*$/', $selectedChoices, $matches)) {
141 throw new InvalidArgumentException(sprintf($errorMessage, $selected)); 145 throw new InvalidArgumentException(sprintf($errorMessage, $selected));
142 } 146 }
143 $selectedChoices = explode(',', $selectedChoices); 147 $selectedChoices = explode(',', $selectedChoices);
144 } else { 148 } else {
145 $selectedChoices = array($selected); 149 $selectedChoices = array($selected);