Exemple #1
0
 /**
  * Register rule
  * 
  * @param Rulable $rule
  * @return Rulable
  */
 private function register(Rulable $rule)
 {
     $key = $rule->info('key');
     $name = is_array($key) ? implode('\\', $key) : $key;
     $this->rules[$name] = $rule;
     return $this->rules[$name];
 }
Exemple #2
0
 /**
  * Fill the side missing
  * 
  * @param Rulable $rule
  * @return callable
  */
 public static function fillSide(Rulable $rule)
 {
     $default = $rule->info('default');
     $delimiter = $rule->info('delimiter');
     return function ($values) use($default, $delimiter) {
         if (implode($delimiter, $values) === $delimiter) {
             return null;
         }
         $fill = array_filter(explode($delimiter, $default), 'strlen');
         if (count($fill) === 2) {
             !$values[0] && $values[0] !== '0' and $values[0] = $fill[0];
             !$values[1] && $values[1] !== '0' and $values[1] = $fill[1];
         }
         return $values;
     };
 }
Exemple #3
0
 /**
  * Check num multiple
  * 
  * @param Rulable $rule
  * @return callable
  */
 public static function numberMultiple(Rulable $rule)
 {
     $allow = $rule->info('allow');
     return function (array $input) use($allow) {
         $values = array_map(function ($v) {
             return (int) $v;
         }, $input);
         if (!$allow) {
             return $values;
         }
         foreach ($values as $v) {
             if ($v < $allow[0] || $allow[1] < $v) {
                 return null;
             }
         }
         return $values;
     };
 }