Esempio n. 1
0
 public function testPreg()
 {
     $rule = Rule::instance();
     $this->assertSame("something", $rule->preg("~^something\$~")->filter("something"));
     $this->assertNull($rule->preg("~^something~")->filter("nothing", $default = null));
 }
Esempio n. 2
0
 /**
  * 非负整数
  *
  * @return Rule
  */
 public static function id()
 {
     return Rule::instance()->setup(FILTER_VALIDATE_INT, array('min_range' => 1));
 }
Esempio n. 3
0
 /**
  * 任意字符
  *
  * @codeCoverageIgnore
  * @return Rule
  */
 public static function raw()
 {
     return Rule::instance()->setup(FILTER_UNSAFE_RAW);
 }
Esempio n. 4
0
 /**
  * @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);
     }
 }