0 follower

Final Class Yiisoft\Validator\Helper\MessageProcessor

InheritanceYiisoft\Validator\Helper\MessageProcessor

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( \Yiisoft\Translator\TranslatorInterface $translator, string $translationCategory, \Yiisoft\Translator\MessageFormatterInterface $messageFormatter, string $messageFormatterLocale )
$translator \Yiisoft\Translator\TranslatorInterface

A translator instance used for translations of error messages.

$translationCategory string

A translation category.

$messageFormatter \Yiisoft\Translator\MessageFormatterInterface

A message formatter instance used for formats of error messages.

$messageFormatterLocale string

Locale to use when error message requires format only.

                public function __construct(
    private readonly TranslatorInterface $translator,
    private readonly string $translationCategory,
    private readonly MessageFormatterInterface $messageFormatter,
    private readonly string $messageFormatterLocale,
) {}

            
process() public method

public string process ( Yiisoft\Validator\Error $error )
$error Yiisoft\Validator\Error

                public function process(Error $error): string
{
    return match ($error->getMessageProcessing()) {
        Error::MESSAGE_TRANSLATE => $this->translator->translate(
            $error->getMessage(),
            $error->getParameters(),
            $this->translationCategory,
        ),
        Error::MESSAGE_FORMAT => $this->messageFormatter->format(
            $error->getMessage(),
            $error->getParameters(),
            $this->messageFormatterLocale,
        ),
        default => $error->getMessage(),
    };
}