mirror of
https://github.com/Respect/Validation.git
synced 2024-06-07 08:12:16 +02:00
d7dc0f2b4e
This commit will rename the "Nullable" rule to "NullOr" while soft deprecating the old name. It should work the same as the previous one but with a different name. It will also prefix the result ID, allowing more message customization. While working on it, I realized that the prefix "nullOr" had a typo, and it was using "nullOf" instead. I fixed that, too. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
36 lines
764 B
PHP
36 lines
764 B
PHP
<?php
|
|
|
|
/*
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Respect\Validation\Transformers;
|
|
|
|
use function array_keys;
|
|
use function in_array;
|
|
|
|
final class Aliases implements Transformer
|
|
{
|
|
private const ALIASES = [
|
|
'nullable' => 'nullOr',
|
|
'optional' => 'undefOr',
|
|
];
|
|
|
|
public function __construct(
|
|
private readonly Transformer $next
|
|
) {
|
|
}
|
|
|
|
public function transform(RuleSpec $ruleSpec): RuleSpec
|
|
{
|
|
if (!in_array($ruleSpec->name, array_keys(self::ALIASES), true)) {
|
|
return $this->next->transform($ruleSpec);
|
|
}
|
|
|
|
return new RuleSpec(self::ALIASES[$ruleSpec->name], $ruleSpec->arguments);
|
|
}
|
|
}
|