/** * Create * * @param string|string[] $key * @param string|string[] $default * @param string $type * @param array $candidates * @return self */ public static function create($key, $default, $type, array $candidates) { $rule = new self(); $rule->key = $key; $rule->default = $default; $rule->type = $type; $rule->candidates = $candidates; $rule->delimiter = $rule->types(self::TYPE_SET) ? Straw::getConfigure('set') : null; return $rule; }
<?php require_once '../vendor/autoload.php'; require_once './functions.php'; use Straw\Straw; $s = Straw::open(); //normal $s->alpha('a'); $s->alnum('an'); $s->number('n'); //list $s->alphaList('al'); $s->alnumList('anl'); $s->numberList('nl'); //pair $s->alphaPair('ap'); $s->alnumPair('anp'); $s->numberPair('np'); //range $s->numberRange('nr'); $s->numberRange('nr2'); $s->datetimeRange('dr'); //set&enum $s->set('set', null, array('set1', 'set2', 'set3')); $s->enum('enum', null, array('e1', 'e2', 'e3')); //change key $s->alnum('before')->to('after'); $s->alnum('top')->to('array.inner'); $s->number('val1')->to('values.'); $s->number('val2')->to('values.'); //mix
/** * Set datetime type * * @param string $format * @return $this */ public function datetime($format) { $this->piece = Straw::getConfigure('alnum'); $this->datetime_format = $format; $this->is_datetime = true; return $this; }
public function rules(Straw $s) { $s->alpha('alpha'); $s->number('number'); }