Final Class Yiisoft\Validator\Helper\MessageProcessor
| Inheritance | Yiisoft\Validator\Helper\MessageProcessor |
|---|
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Validator\Helper\MessageProcessor | |
| process() | Yiisoft\Validator\Helper\MessageProcessor |
Method Details
| 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,
) {}
| 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(),
};
}
Signup or Login in order to comment.