mirror of
https://github.com/Respect/Validation.git
synced 2026-03-16 23:35:45 +01:00
The `Id`, `Name`, and `Path` value objects are not only message-related concerns, they're part of the core of the library, hence it makes sense to place them at the root namespace.
42 lines
963 B
PHP
42 lines
963 B
PHP
<?php
|
|
|
|
/*
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
use Attribute;
|
|
use Respect\Validation\Name;
|
|
use Respect\Validation\Result;
|
|
use Respect\Validation\Rule;
|
|
use Respect\Validation\Rules\Core\Nameable;
|
|
use Respect\Validation\Rules\Core\Wrapper;
|
|
|
|
use function is_string;
|
|
|
|
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)]
|
|
final class Named extends Wrapper implements Nameable
|
|
{
|
|
private readonly Name $name;
|
|
|
|
public function __construct(Rule $rule, string|Name $name)
|
|
{
|
|
parent::__construct($rule);
|
|
|
|
$this->name = is_string($name) ? new Name($name) : $name;
|
|
}
|
|
|
|
public function getName(): Name
|
|
{
|
|
return $this->name;
|
|
}
|
|
|
|
public function evaluate(mixed $input): Result
|
|
{
|
|
return $this->rule->evaluate($input)->withName($this->name);
|
|
}
|
|
}
|