removed error collector bloat, switched to plain array. thanks mikelbring.

This commit is contained in:
Taylor Otwell
2011-06-25 20:05:20 -05:00
parent 4a5190dfd9
commit b7b258a10b
5 changed files with 10 additions and 103 deletions

View File

@@ -1,81 +0,0 @@
<?php namespace System\Validation;
class Error_Collector {
/**
* All of the error messages.
*
* @var array
*/
public $messages;
/**
* Create a new Error Collector instance.
*
* @return void
*/
public function __construct($messages = array())
{
$this->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();
}
}