コード例 #1
0
 /**
  * When the input field is an array or csv, this will build a new validator
  * as if the fields were individual ones, each checked against the base rule
  *
  * @param mixed[] $input
  * @param string $field
  * @param string $rules
  */
 private function _sanitize_recursive($input, $field, $rules)
 {
     // create a new instance to run against this sub data
     $validator = new Data_Validator();
     $fields = array();
     $sanitation_rules = array();
     if ($this->_datatype[$field] === 'array') {
         // Convert the array to individual values, they all use the same rules
         foreach ($input[$field] as $key => $value) {
             $sanitation_rules[$key] = $rules;
             $fields[$key] = $value;
         }
         // Sanitize each "new" field
         $validator->sanitation_rules($sanitation_rules);
         $validator->validate($fields);
         // Take the individual results and replace them in the original array
         $input[$field] = array_replace($input[$field], $validator->validation_data());
     } elseif ($this->_datatype[$field] === 'csv') {
         // Break up the CSV data so we have an array
         $temp = explode(',', $input[$field]);
         foreach ($temp as $key => $value) {
             $sanitation_rules[$key] = $rules;
             $fields[$key] = $value;
         }
         // Sanitize each "new" field
         $validator->sanitation_rules($sanitation_rules);
         $validator->validate($fields);
         // Put it back together with clean data
         $input[$field] = implode(',', $validator->validation_data());
     }
     return $input[$field];
 }