Exemplo n.º 1
0
 /**
  * @return array
  */
 protected static function exportRules($rules)
 {
     $payload = array();
     foreach ($rules as $rule) {
         if (!is_string($op = $rule->operation)) {
             $op = new Callback($op);
             if (!$op->isStatic()) {
                 continue;
             }
         }
         if ($rule->type === Rule::VALIDATOR) {
             $item = array('op' => ($rule->isNegative ? '~' : '') . $op, 'msg' => $rules->formatMessage($rule, FALSE));
         } elseif ($rule->type === Rule::CONDITION) {
             $item = array('op' => ($rule->isNegative ? '~' : '') . $op, 'rules' => self::exportRules($rule->subRules), 'control' => $rule->control->getHtmlName());
             if ($rule->subRules->getToggles()) {
                 $item['toggle'] = $rule->subRules->getToggles();
             }
         }
         if (is_array($rule->arg)) {
             foreach ($rule->arg as $key => $value) {
                 $item['arg'][$key] = $value instanceof IFormControl ? (object) array('control' => $value->getHtmlName()) : $value;
             }
         } elseif ($rule->arg !== NULL) {
             $item['arg'] = $rule->arg instanceof IFormControl ? (object) array('control' => $rule->arg->getHtmlName()) : $rule->arg;
         }
         $payload[] = $item;
     }
     return $payload;
 }