I would put an if
statement around your validation:
$fields = $object->getValidationFields();
if ($fields) {
$validator = new fValidation();
$validator->addRequiredFields($fields);
$validator->validate();
}
I'm not positive what you are asking in your second question, but I'll try to answer it. If you need to combine validation sources, you can use ->validate(TRUE)
, merge the validation arrays and then pass them to fValidationException.
$validator = new fValidation();
$validator->addRequiredFields($fields);
$messages = array_merge(
$validator->validate(TRUE),
$active_record->validate(TRUE)
);
if ($messages) {
throw new fValidationException('The following problems were found:', $messages);
}