mirror of
https://github.com/Respect/Validation.git
synced 2026-03-17 23:59:51 +01:00
By extracting them into different processors, the code in the rendered becomes much more straightforward, and the design makes it possible to create processors easily. This change will allow users to customize that behavior if they want to. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
35 lines
807 B
PHP
35 lines
807 B
PHP
<?php
|
|
|
|
/*
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Respect\Validation\Message\Parameter;
|
|
|
|
use function call_user_func;
|
|
use function is_string;
|
|
|
|
final class Trans implements Processor
|
|
{
|
|
/** @var callable */
|
|
private $translator;
|
|
|
|
public function __construct(
|
|
callable $translator,
|
|
private readonly Processor $nextProcessor,
|
|
) {
|
|
$this->translator = $translator;
|
|
}
|
|
|
|
public function process(string $name, mixed $value, ?string $modifier = null): string
|
|
{
|
|
if ($modifier === 'trans' && is_string($value)) {
|
|
return call_user_func($this->translator, $value);
|
|
}
|
|
|
|
return $this->nextProcessor->process($name, $value, $modifier);
|
|
}
|
|
}
|