Пример #1
0
 public static function Name($name)
 {
     self::$format = array();
     self::$format['a'] = 'ÀÁÂÃÄÅÆÇçÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜüÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûýýþÿŔŕ"!@#$%&*()_-+={[}]/?;:.,\\\'<>°ºª';
     self::$format['b'] = 'aaaaaaacceeeeiiiidnoooooouuuuuybsaaaaaaaceeeeiiiidnoooooouuuyybyRr                                 ';
     self::$data = strtr(utf8_decode($name), utf8_decode(self::$format['a']), self::$format['b']);
     self::$data = strip_tags(trim(self::$data));
     self::$data = str_replace(' ', '-', self::$data);
     self::$data = str_replace(array('-----', '----', '---', '--'), '-', self::$data);
     return strtolower(utf8_encode(self::$data));
 }
Пример #2
0
 public static function valid($rules, $data)
 {
     static::$errors = [];
     static::triggerOnce('init');
     self::$data = $data = (array) $data;
     foreach ((array) $rules as $field_name => $rule) {
         $current = isset($data[$field_name]) ? $data[$field_name] : null;
         if (is_callable($rule)) {
             static::$errors[$field_name] = call_user_func($rule, $current);
             continue;
         } elseif (is_string($rule)) {
             $current_rules = array_flip(preg_split('/\\s*\\|\\s*/', $rule));
         } else {
             $current_rules = (array) $rule;
         }
         static::$errors[$field_name] = true;
         foreach ($current_rules as $method => $message) {
             $meth_name = strtok($method, ':');
             $opts = strtok(':') ?: '';
             $opts = $opts ? json_decode("[{$opts}]") : [];
             $meth_opts = $opts ? array_merge([$current], $opts) : [$current];
             if (static::$errors[$field_name] !== true) {
                 continue 2;
             }
             if (empty(static::$methods[$meth_name])) {
                 static::$errors[$field_name] = true;
             } else {
                 if (call_user_func_array(static::$methods[$meth_name]->validate, $meth_opts)) {
                     static::$errors[$field_name] = true;
                 } else {
                     $arg = [];
                     foreach ($meth_opts as $key => $value) {
                         $arg["arg_{$key}"] = $value;
                     }
                     static::$errors[$field_name] = Text::render(static::$methods[$meth_name]->message, $arg);
                 }
             }
         }
     }
     self::$data = [];
     // Clean non-errors
     static::$errors = array_filter(static::$errors, function ($v) {
         return $v !== true;
     });
     return empty(static::$errors);
 }