GetOptionKit\Option::validate PHP Method

validate() public method

public validate ( $value )
    public function validate($value)
    {
        if ($this->validator) {
            $ret = call_user_func($this->validator, $value);
            if (is_array($ret)) {
                return $ret;
            } else {
                if ($ret === false) {
                    return array(false, "Invalid value: {$value}");
                } else {
                    if ($ret === true) {
                        return array(true, 'Successfully validated.');
                    }
                }
            }
            throw new InvalidArgumentException('Invalid return value from the validator.');
        }
        return array(true);
    }

Usage Example

コード例 #1
0
ファイル: OptionTest.php プロジェクト: c9s/getoptionkit
 public function testOptionWithoutValidator()
 {
     $opt = new Option('scope');
     $ret = $opt->validate('public');
     $this->assertTrue($ret[0]);
     $ret = $opt->validate('private');
     $this->assertTrue($ret[0]);
     $ret = $opt->validate('foo');
     $this->assertTrue($ret[0]);
     $this->assertEquals('--scope', $opt->renderReadableSpec(true));
 }