/** * Assigns an error array to a static local reference */ public static function set_errors($array) { self::$_errors = $array; }
/** * * @static * @return boolean */ public static function run() { self::$_errors = array(); if (!empty(self::$_rules)) { foreach (self::$_rules as $key => $value) { self::_registerVar($key); $parse = self::_parseRule($value); $post_item = Input::post($key) ? Input::post($key) : NULL; if (isset($parse['required'])) { if (!$post_item) { self::$_errors[] = sprintf('%s is required.', ucfirst($key)); } } if (!$post_item) { continue; } if (isset($parse['trim'])) { $post_item = trim($post_item); } if (isset($parse['integer'])) { if (!is_int($post_item)) { self::$_errors[] = sprintf('%s must contain an integer.', ucfirst($key)); } } if (isset($parse['numeric'])) { if (!is_numeric($post_item)) { self::$_errors[] = sprintf('%s must contain a numeric.', ucfirst($key)); } } if (isset($parse['alpha'])) { if (!preg_match("/^([a-z])+\$/i", $post_item)) { self::$_errors[] = sprintf('%s may only contain alphabetical characters.', ucfirst($key)); } } if (isset($parse['matches'])) { if ($post_item !== Input::post($parse['matches'])) { self::$_errors[] = sprintf('%s does not match the %s', ucfirst($key), ucfirst(Input::post($parse['matches']))); } } if (isset($parse['minLength'])) { if (strlen($post_item) < $parse['minLength']) { self::$_errors[] = sprintf('%s must be at least %s characters in length.', ucfirst($key), $parse['minLength']); } } if (isset($parse['maxLength'])) { if (strlen($post_item) > $parse['maxLength']) { self::$_errors[] = sprintf('%s can not exceed %s characters in length.', ucfirst($key), $parse['maxLength']); } } if (isset($parse['validEmail'])) { if (!filter_var($post_item, FILTER_VALIDATE_EMAIL)) { self::$_errors[] = sprintf('%s must contain a valid email address.', ucfirst($key)); } } if (isset($parse['verifyCaptcha'])) { if ($post_item !== Session::get('captcha')) { self::$_errors[] = sprintf('%s is wrong.', ucfirst($key)); } else { Session::set('verifyCaptcha', TRUE); } } } } if (self::$_errors) { return FALSE; } return TRUE; }