public function run($data, ResultInterface $result = null)
{
if ($result === null) {
$result = new Result();
}
$result->setResult(true);
foreach ($this->fields as $fieldName => $rules) {
$fieldResult = $this->validateField($fieldName, $data, $result);
if (!$fieldResult) {
// There was a failure so log it to the result object
$result->setResult(false);
}
}
return $result;
}
/** * Validates a dataset * * @param [] $data * * @throws InvalidArgumentException */ public function validate(array $data) { $result = $this->validator->run($data); if ($result->isValid() === false) { $error = $result->getErrors(); $error = reset($error); throw new InvalidArgumentException($error); } }