예제 #1
0
파일: Validator.php 프로젝트: ksingh812/epb
 /**
  * Validation will only be performed on input keys not on all field keys to
  * allow for partial input validation.
  *
  * @param array input
  * @return array errors (empty if no errors)
  */
 function validate($input)
 {
     $errors = array();
     $defaults = pixcustomify::defaults();
     $plugin_checks = $this->meta->get('checks', array());
     foreach ($input as $key => $value) {
         $field = $this->fields->get($key);
         // Calculate validation rules
         // --------------------------
         $rules = array();
         // check pixcustomify defaults
         if (isset($defaults['checks'][$field['type']])) {
             $rules = $defaults['checks'][$field['type']];
         }
         // check theme defaults
         if (isset($plugin_checks[$field['type']])) {
             $rules = array_merge($rules, $plugin_checks[$field['type']]);
         }
         // check field presets
         if (isset($field['checks'])) {
             $rules = array_merge($rules, $field['checks']);
         }
         // Perform validation
         // ------------------
         foreach ($rules as $rule) {
             $callback = pixcustomify::callback($rule, $this->meta);
             $valid = call_user_func($callback, $input[$key], $field, $this);
             if (!$valid) {
                 isset($errors[$key]) or $errors[$key] = array();
                 $errors[$key][$rule] = $this->error_message($rule);
             }
         }
     }
     return $errors;
 }
예제 #2
0
파일: Processor.php 프로젝트: ksingh812/epb
 /**
  * Execute postupdate hooks on input.
  */
 protected function postupdate($input)
 {
     $defaults = pixcustomify::defaults();
     $plugin_hooks = $this->meta->get('processor', array('preupdate' => array(), 'postupdate' => array()));
     // Calculate hooks
     // ---------------
     $hooks = array();
     // check pixcustomify defaults
     if (isset($defaults['processor']['postupdate'])) {
         $hooks = $defaults['processor']['postupdate'];
     }
     // check plugin defaults
     if (isset($plugin_hooks['postupdate'])) {
         $hooks = array_merge($hooks, $plugin_hooks['postupdate']);
     }
     // Execute hooks
     // -------------
     foreach ($hooks as $rule) {
         $callback = pixcustomify::callback($rule, $this->meta);
         call_user_func($callback, $input, $this);
     }
 }