Example #1
0
 /**
  * !! THIS METHOD IS CALLED AUTOMATICALLY BY "Validator" object !!
  *
  * Used for enum columns. Checks if the value is part of possible values from DB.
  * @param Validator $validator
  * @param $field
  * @param $rule
  * @param $label
  * @param $message
  * @return bool
  * @throws \Exception
  */
 public function validateEnum(Validator $validator, $field, $rule, $label, $message)
 {
     $table = isset($rule['table']) ? $rule['table'] : $this->_tableName;
     $column = isset($rule['column']) ? $rule['column'] : $field;
     $options = $this->_db->getColumnOptions($table, $column);
     if (in_array($validator->getValue($field), $options)) {
         return true;
         // all is good
     }
     throw new \Exception($message ? $message : $validator->translate("Invalid {$label}!"));
 }