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/ComposedValidator.php

27 lines
685 B

<?php
namespace IQBall\Core\Validation;
class ComposedValidator extends Validator {
private Validator $first;
private Validator $then;
/**
* @param Validator $first
* @param Validator $then
*/
public function __construct(Validator $first, Validator $then) {
$this->first = $first;
$this->then = $then;
}
public function validate(string $name, $val): array {
$firstFailures = $this->first->validate($name, $val);
$thenFailures = [];
if (empty($firstFailures)) {
$thenFailures = $this->then->validate($name, $val);
}
return array_merge($firstFailures, $thenFailures);
}
}