diff options
Diffstat (limited to 'vendor/symfony/console/Question/ChoiceQuestion.php')
-rw-r--r-- | vendor/symfony/console/Question/ChoiceQuestion.php | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/vendor/symfony/console/Question/ChoiceQuestion.php b/vendor/symfony/console/Question/ChoiceQuestion.php index 2c40638d..46cc72a3 100644 --- a/vendor/symfony/console/Question/ChoiceQuestion.php +++ b/vendor/symfony/console/Question/ChoiceQuestion.php @@ -26,14 +26,16 @@ class ChoiceQuestion extends Question private $errorMessage = 'Value "%s" is invalid'; /** - * Constructor. - * * @param string $question The question to ask to the user * @param array $choices The list of available choices * @param mixed $default The default answer to return */ public function __construct($question, array $choices, $default = null) { + if (!$choices) { + throw new \LogicException('Choice question must have at least 1 choice available.'); + } + parent::__construct($question, $default); $this->choices = $choices; @@ -58,7 +60,7 @@ class ChoiceQuestion extends Question * * @param bool $multiselect * - * @return ChoiceQuestion The current instance + * @return $this */ public function setMultiselect($multiselect) { @@ -69,6 +71,16 @@ class ChoiceQuestion extends Question } /** + * Returns whether the choices are multiselect. + * + * @return bool + */ + public function isMultiselect() + { + return $this->multiselect; + } + + /** * Gets the prompt for choices. * * @return string @@ -83,7 +95,7 @@ class ChoiceQuestion extends Question * * @param string $prompt * - * @return ChoiceQuestion The current instance + * @return $this */ public function setPrompt($prompt) { @@ -99,7 +111,7 @@ class ChoiceQuestion extends Question * * @param string $errorMessage * - * @return ChoiceQuestion The current instance + * @return $this */ public function setErrorMessage($errorMessage) { @@ -127,7 +139,7 @@ class ChoiceQuestion extends Question if ($multiselect) { // Check for a separated comma values - if (!preg_match('/^[a-zA-Z0-9_-]+(?:,[a-zA-Z0-9_-]+)*$/', $selectedChoices, $matches)) { + if (!preg_match('/^[^,]+(?:,[^,]+)*$/', $selectedChoices, $matches)) { throw new InvalidArgumentException(sprintf($errorMessage, $selected)); } $selectedChoices = explode(',', $selectedChoices); |