Esempio n. 1
0
 /**
  * HTML 字符
  * @return Rule
  */
 public static function html()
 {
     return Rule::callback(function ($html) {
         if (self::$htmlPurifier === null) {
             self::$htmlPurifier = new \HTMLPurifier(\HTMLPurifier_Config::createDefault());
         }
         return self::$htmlPurifier->purify($html);
     });
 }
Esempio n. 2
0
 /**
  * 整数
  *
  * @param int $min
  * @param int $max
  * @return Rule
  */
 public static function int($min = -2147483647, $max = 2147483647)
 {
     return Rule::callback(function ($data) use($min, $max) {
         if ($data === 0 or $data === "0") {
             $data = 0;
             if ($data >= $min and $data <= $max) {
                 return $data;
             } else {
                 return false;
             }
         }
         return filter_var($data, FILTER_VALIDATE_INT, array('options' => array_filter(array('min_range' => $min, 'max_range' => $max))));
     });
 }