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.
43 lines
971 B
PHP
43 lines
971 B
PHP
<?php
|
|
|
|
/*
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Respect\Validation\Rules\Core;
|
|
|
|
use Respect\Validation\Name;
|
|
use Respect\Validation\Rule;
|
|
use Respect\Validation\Rules\AllOf;
|
|
use Respect\Validation\Rules\Named;
|
|
use Respect\Validation\Rules\Templated;
|
|
|
|
final class Reducer extends Wrapper
|
|
{
|
|
public function __construct(Rule $rule1, Rule ...$rules)
|
|
{
|
|
parent::__construct($rules === [] ? $rule1 : new AllOf($rule1, ...$rules));
|
|
}
|
|
|
|
public function withTemplate(string $template): self
|
|
{
|
|
return new self(new Templated($this->rule, $template));
|
|
}
|
|
|
|
public function withName(Name $name): self
|
|
{
|
|
return new self(new Named($this->rule, $name));
|
|
}
|
|
|
|
public function getName(): Name|null
|
|
{
|
|
if ($this->rule instanceof Nameable) {
|
|
return $this->rule->getName();
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|