forked from Respect/Validation
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCircuit.php
More file actions
40 lines (32 loc) · 1.06 KB
/
Copy pathCircuit.php
File metadata and controls
40 lines (32 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
/*
* SPDX-License-Identifier: MIT
* SPDX-FileCopyrightText: (c) Respect Project Contributors
* SPDX-FileContributor: Fabio Ribeiro <faabiosr@gmail.com>
* SPDX-FileContributor: Henrique Moody <henriquemoody@gmail.com>
*/
declare(strict_types=1);
namespace Respect\Validation\Validators;
use Attribute;
use Respect\Validation\Result;
use Respect\Validation\Validator;
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)]
final readonly class Circuit implements Validator
{
/** @var non-empty-array<Validator> */
private readonly array $validators;
public function __construct(Validator $validator1, Validator $validator2, Validator ...$validators)
{
$this->validators = [$validator1, $validator2, ...$validators];
}
public function evaluate(mixed $input): Result
{
foreach ($this->validators as $validator) {
$result = $validator->evaluate($input);
if (!$result->hasPassed) {
return $result;
}
}
return $result;
}
}