Liip\RMT\Information\InformationRequest::validate PHP Метод

validate() публичный Метод

public validate ( $value )
    public function validate($value)
    {
        switch ($this->options['type']) {
            case 'boolean':
                $this->validateValue($value, 'is_bool', 'Must be a boolean');
                break;
            case 'choice':
                $this->validateValue(array($value, $this->options['choices']), function ($v, $choices) {
                    return in_array($v, $choices);
                }, 'Must be one of ' . json_encode($this->options['choices']));
                break;
            case 'text':
                $this->validateValue($value, function ($v) {
                    return is_string($v) && strlen($v) > 0;
                }, 'Test must be provided');
                break;
            case 'yes-no':
                $value = lcfirst($value[0]);
                $this->validateValue($value, function ($v) {
                    return $v === 'y' || $v === 'n';
                }, "Must be 'y' or 'n'");
                break;
        }
        return $value;
    }