123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php namespace System\Validation;
- class Error_Collector {
-
- public $messages;
-
- public function __construct($messages = array())
- {
- $this->messages = $messages;
- }
-
- public function add($attribute, $message)
- {
- $this->messages[$attribute][] = $message;
- }
-
- public function has($attribute)
- {
- return $this->first($attribute) !== '';
- }
-
- public function first($attribute)
- {
- return (count($messages = $this->get($attribute)) > 0) ? $messages[0] : '';
- }
-
- 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();
- }
- }
|