/** * @param array $values Values to validate. * @param array $rules Validation rules. * @param ErrorCollection $errors */ public function __invoke(array $values, array $rules, ErrorCollection $errors) { $validation = $this->build_validation($rules); foreach ($validation->validate(new ArrayAdapter($values)) as $attribute => $messages) { foreach ($messages as $message) { $errors->add($attribute, $message->format, $message->args); } } }
/** * Returns an error collection instance. * * @return ErrorCollection */ public function to_error_collection() { $collection = new ErrorCollection(); /* @var $messages Message[] */ foreach ($this as $attribute => $messages) { foreach ($messages as $message) { $collection->add($attribute, $message->format, $message->args); } } return $collection; }