From b7b258a10b8388f24ce9af56acefd4e1b45f649f Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 25 Jun 2011 20:05:20 -0500 Subject: [PATCH] removed error collector bloat, switched to plain array. thanks mikelbring. --- system/html.php | 4 +- system/validation/error_collector.php | 81 --------------------------- system/validation/rule.php | 8 +-- system/validator.php | 10 ++-- system/view.php | 10 ---- 5 files changed, 10 insertions(+), 103 deletions(-) delete mode 100644 system/validation/error_collector.php diff --git a/system/html.php b/system/html.php index 298046f5..604a9ed2 100644 --- a/system/html.php +++ b/system/html.php @@ -21,7 +21,7 @@ class HTML { */ public static function script($url) { - return ''.PHP_EOL; + return ''.PHP_EOL; } /** @@ -32,7 +32,7 @@ class HTML { */ public static function style($url, $media = 'all') { - return ''.PHP_EOL; + return ''.PHP_EOL; } /** diff --git a/system/validation/error_collector.php b/system/validation/error_collector.php deleted file mode 100644 index 48fd8dbe..00000000 --- a/system/validation/error_collector.php +++ /dev/null @@ -1,81 +0,0 @@ -messages = $messages; - } - - /** - * Add an error message to the collector. - * - * @param string $attribute - * @param string $message - * @return void - */ - public function add($attribute, $message) - { - $this->messages[$attribute][] = $message; - } - - /** - * Determine if errors exist for an attribute. - * - * @param string $attribute - * @return bool - */ - public function has($attribute) - { - return $this->first($attribute) !== ''; - } - - /** - * Get the first error message for an attribute. - * - * @param string $attribute - * @return string - */ - public function first($attribute) - { - return (count($messages = $this->get($attribute)) > 0) ? $messages[0] : ''; - } - - /** - * Get all of the error messages for an attribute. - * - * If no attribute is specified, all of the error messages will be returned. - * - * @param string $attribute - * @return array - */ - public function get($attribute = null) - { - if (is_null($attribute)) - { - $all = array(); - - foreach ($this->messages as $messages) - { - $all = array_merge($all, $messages); - } - - return $all; - } - - return (array_key_exists($attribute, $this->messages)) ? $this->messages[$attribute] : array(); - } - -} \ No newline at end of file diff --git a/system/validation/rule.php b/system/validation/rule.php index 4932eaf5..da3e6cf3 100644 --- a/system/validation/rule.php +++ b/system/validation/rule.php @@ -32,17 +32,17 @@ abstract class Rule { /** * Run the validation rule. * - * @param array $attributes - * @param Error_Collector $errors + * @param array $attributes + * @param array $errors * @return void */ - public function validate($attributes, $errors) + public function validate($attributes, &$errors) { foreach ($this->attributes as $attribute) { if ( ! $this->check($attribute, $attributes)) { - $errors->add($attribute, $this->prepare_message($attribute)); + $errors[$attribute][] = $this->prepare_message($attribute); } } } diff --git a/system/validator.php b/system/validator.php index 1a26ca39..c7e9a2bf 100644 --- a/system/validator.php +++ b/system/validator.php @@ -10,9 +10,9 @@ class Validator { public $attributes; /** - * The validation error collector. + * The validation errors * - * @var Error_Collector + * @var array */ public $errors; @@ -36,8 +36,6 @@ class Validator { // attributes as the validation attributes. // --------------------------------------------------------- $this->attributes = ($target instanceof DB\Eloquent) ? $target->attributes : (array) $target; - - $this->errors = new Validation\Error_Collector; } /** @@ -58,7 +56,7 @@ class Validator { */ public function is_valid() { - $this->errors->messages = array(); + $this->errors = array(); foreach ($this->rules as $rule) { @@ -69,7 +67,7 @@ class Validator { $rule->validate($this->attributes, $this->errors); } - return count($this->errors->messages) == 0; + return count($this->errors) == 0; } /** diff --git a/system/view.php b/system/view.php index 95b508cf..990b2dcd 100644 --- a/system/view.php +++ b/system/view.php @@ -34,16 +34,6 @@ class View { { $this->view = $view; $this->data = $data; - - // ----------------------------------------------------- - // Every view has an error collector. This makes it - // convenient to check for any validation errors without - // worrying if the error collector is instantiated. - // - // If an error collector is in the session, it will - // be used as the error collector for the view. - // ----------------------------------------------------- - $this->data['errors'] = (Config::get('session.driver') != '' and Session::has('errors')) ? Session::get('errors') : new Validation\Error_Collector; } /**