You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Application-Web/src/Core/Validation/Validation.php

30 lines
937 B

<?php
namespace IQBall\Core\Validation;
/**
* Utility class for validation
*/
class Validation {
/**
* Validate a value from validators, appending failures in the given errors array.
* @param mixed $val the value to validate
* @param string $valName the name of the value
* @param ValidationFail[] $failures array to push when a validator fails
* @param Validator ...$validators given validators
* @return bool true if any of the given validators did fail
*/
public static function validate($val, string $valName, array &$failures, Validator...$validators): bool {
$had_errors = false;
foreach ($validators as $validator) {
$error = $validator->validate($valName, $val);
if ($error != null) {
$failures = array_merge($failures, $error);
$had_errors = true;
}
}
return $had_errors;
}
}