function classify($class_name, $singularize = false) { if ($singularize) { $class_name = Utils::singularize($class_name); } $class_name = Inflector::instance()->camelize($class_name); return ucfirst($class_name); }
/** * Returns all the error messages as an array, including error key. * * <code> * $model->errors->errors(); * * # array( * # "name" => array("Name can't be blank"), * # "state" => array("State is the wrong length (should be 2 chars)") * # ) * </code> * * @param array $closure Closure to fetch the errors in some other format (optional) * This closure has the signature function($attribute, $message) * and is called for each available error message. * @return array */ public function to_array($closure = null) { $errors = array(); if ($this->errors) { foreach ($this->errors as $attribute => $messages) { foreach ($messages as $msg) { if (is_null($msg)) { continue; } $errors[$attribute][] = $message = Utils::human_attribute($attribute) . ' ' . $msg; if ($closure) { $closure($attribute, $message); } } } } return $errors; }