field_name = $field_name; $this->custom_error = $custom_error; } /** * @return string Field name */ function getField() { return $this->field_name; } /** * Alias for adding single field error to error list * Fills field array with array('Field' => $this->field_name) that is ok for single field rules * If $custom_error attribute is set will use $custom_error regardless of $message * If $custom_error attribute is not set will apply lmb_i18n function to $message * @param string Error message * @param array Array of values * @see lmbErrorList :: addError() * @return void */ function error($message, $values = array(), $i18n_params = array()) { $error = $this->custom_error ? $this->custom_error : lmb_i18n($message, $i18n_params, 'validation'); $this->error_list->addError($error, array('Field' => $this->field_name), $values); } /** * Validates field * Calls {@link check()} method if $datasource has such field with not empty value. * Child classes must implement check($value) method to perform real validation. * To check field for existance and having none empty value use {@link lmbRequiredRule} * Fills {@link $error_list} * @see lmbValidationRule :: validate */ function validate($datasource, $error_list) { $this->error_list = $error_list; $value = $datasource->get($this->field_name); if(isset($value) && $value !== '') $this->check($value); } /** * Performs real validation * @param mixed Field value check * @return void */ abstract function check($value); } ?>