Add validateArray method

[MAILPOET-4700]
This commit is contained in:
David Remer
2022-10-25 14:28:41 +03:00
committed by Jan Jakeš
parent 75906820e5
commit c8565b1197

View File

@@ -25,7 +25,18 @@ class Validator {
* @return mixed
*/
public function validate(Schema $schema, $value, string $paramName = 'value') {
$result = $this->validateAndSanitizeValueFromSchema($value, $schema->toArray(), $paramName);
return $this->validateArray($schema->toArray(), $value, $paramName);
}
/**
* Strict validation & sanitization implementation.
* It only coerces int to float (e.g. 5 to 5.0).
*
* @param mixed $value
* @return mixed
*/
public function validateArray(array $schema, $value, string $paramName = 'value') {
$result = $this->validateAndSanitizeValueFromSchema($value, $schema, $paramName);
if ($result instanceof WP_Error) {
throw ValidationException::createFromWpError($result);
}