public function testPreg() { $rule = Rule::instance(); $this->assertSame("something", $rule->preg("~^something\$~")->filter("something")); $this->assertNull($rule->preg("~^something~")->filter("nothing", $default = null)); }
/** * 非负整数 * * @return Rule */ public static function id() { return Rule::instance()->setup(FILTER_VALIDATE_INT, array('min_range' => 1)); }
/** * 任意字符 * * @codeCoverageIgnore * @return Rule */ public static function raw() { return Rule::instance()->setup(FILTER_UNSAFE_RAW); }
/** * @param mixed $data * @param string $key * @param string $message */ public function handle($data, $key = null, $message = '') { if (RuleSet::getHandlers() === null) { RuleSet::attachHandler(new Handler\Exception()); // attach a default handler } foreach (RuleSet::getHandlers() as $handler) { call_user_func(array($handler, 'handle'), Rule::instance(), $data, $key, $message); } }