Matthias\SymfonyConsoleForm\Console\Helper\Question\AlwaysReturnKeyOfChoiceQuestion::getValidator PHP Méthode

getValidator() public méthode

public getValidator ( ) : callable
Résultat callable
    public function getValidator()
    {
        return function ($selected) {
            // Collapse all spaces.
            $selectedChoices = str_replace(' ', '', $selected);
            if ($this->_multiselect) {
                // Check for a separated comma values
                if (!preg_match('/^[a-zA-Z0-9_-]+(?:,[a-zA-Z0-9_-]+)*$/', $selectedChoices)) {
                    throw new \InvalidArgumentException(sprintf($this->_errorMessage, $selected));
                }
                $selectedChoices = explode(',', $selectedChoices);
            } else {
                $selectedChoices = [$selected];
            }
            $selectedKeys = [];
            foreach ($selectedChoices as $selectedValue) {
                $selectedKeys[] = $this->resolveChoiceViewValue($selectedValue);
            }
            if ($this->_multiselect) {
                return $selectedKeys;
            }
            return current($selectedKeys);
        };
    }