-
Notifications
You must be signed in to change notification settings - Fork 776
Expand file tree
/
Copy pathListOrModifier.php
More file actions
38 lines (30 loc) · 945 Bytes
/
ListOrModifier.php
File metadata and controls
38 lines (30 loc) · 945 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
<?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\Message\Modifier;
use Respect\Validation\Message\Modifier;
use Respect\Validation\Message\Placeholder\Listed;
use Respect\Validation\Message\Translator;
use function is_array;
final readonly class ListOrModifier implements Modifier
{
public function __construct(
private Translator $translator,
private Modifier $nextModifier,
) {
}
public function modify(mixed $value, string|null $pipe): string
{
if ($pipe !== 'listOr' || !is_array($value)) {
return $this->nextModifier->modify($value, $pipe);
}
return $this->nextModifier->modify(
new Listed($value, $this->translator->translate('or')),
null,
);
}
}