/** * Runs the given validator and throws an exception if it fails. * * @param $value * @param CValidator $validator */ protected function checkValidator($value, CValidator $validator) { if (!$validator->validate($value)) { self::exception(ZBX_API_ERROR_INTERNAL, $validator->getError()); } }
public function validate() { $data = $this->data; $valid = true; $this->error = array(); require_once CORE_PATH . 'CValidator.php'; $Validator = new CValidator($this->data); foreach ((array) $this->fields as $key => $field) { /* if (isset($field['required']) && ($field['required'] == true)) { $Validator->addRule(new Required($field['name'], $field['title'] . ' обязательное поле')); }*/ if (isset($field['validator_name']) && $field['validator_name'] != '') { $Validator->addRule(new $field['validator']($field['name'], $field['validator_msg'])); } } $valid = $Validator->validate(); $this->error = $Validator->getError(); return $valid; }