forked from Respect/Validation
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNamed.php
More file actions
42 lines (33 loc) · 988 Bytes
/
Copy pathNamed.php
File metadata and controls
42 lines (33 loc) · 988 Bytes
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
41
42
<?php
/*
* SPDX-License-Identifier: MIT
* SPDX-FileCopyrightText: (c) Respect Project Contributors
* SPDX-FileContributor: Henrique Moody <henriquemoody@gmail.com>
*/
declare(strict_types=1);
namespace Respect\Validation\Validators;
use Attribute;
use Respect\Validation\Name;
use Respect\Validation\Result;
use Respect\Validation\Validator;
use Respect\Validation\Validators\Core\Nameable;
use function is_string;
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)]
final readonly class Named implements Nameable
{
private Name $name;
public function __construct(
string|Name $name,
private Validator $validator,
) {
$this->name = is_string($name) ? new Name($name) : $name;
}
public function getName(): Name
{
return $this->name;
}
public function evaluate(mixed $input): Result
{
return $this->validator->evaluate($input)->withName($this->name);
}
}