示例#1
0
 /**
  * apply filters on a single value.
  *
  * @param string      $value
  * @param array|Rules $rules
  * @return null|Utils\ValueTO
  */
 public function applyFilters($value, $rules = array())
 {
     /** @var $filter Utils\Filter */
     $valueTO = $this->valueTO->forge($value);
     // loop through all the rules to validate $value.
     foreach ($rules as $rule => $parameter) {
         // some filters are not to be applied...
         if ($parameter === false) {
             continue;
         }
         // skip rules with option as FALSE.
         // apply filter.
         $method = 'filter_' . $rule;
         if (method_exists($this->filter, $method)) {
             $this->filter->{$method}($valueTO, $parameter);
         } elseif (is_object($parameter) && is_callable($parameter)) {
             $this->filter->applyClosure($valueTO, $parameter);
         }
         // loop break.
         if ($valueTO->getBreak()) {
             break;
         }
     }
     return $valueTO;
 }
示例#2
0
 /**
  * @param ValueTO $v
  * @param         $p
  */
 public function filter_min($v, $p)
 {
     $val = (int) $v->getValue();
     if ($val < (int) $p) {
         $v->setError(__METHOD__);
     }
 }