-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
3,134 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Validator\Helper; | ||
|
||
use Yiisoft\Translator\MessageFormatterInterface; | ||
use Yiisoft\Translator\TranslatorInterface; | ||
use Yiisoft\Validator\Error; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class MessageProcessor | ||
{ | ||
/** | ||
* @param TranslatorInterface $translator A translator instance used for translations of error messages. | ||
* @param string $translationCategory A translation category. | ||
* @param MessageFormatterInterface $messageFormatter A message formatter instance used for formats of error | ||
* messages. | ||
* @param string $messageFormatterLocale Locale to use when error message requires format only. | ||
*/ | ||
public function __construct( | ||
private TranslatorInterface $translator, | ||
private string $translationCategory, | ||
private MessageFormatterInterface $messageFormatter, | ||
private string $messageFormatterLocale, | ||
) { | ||
} | ||
|
||
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(), | ||
}; | ||
} | ||
} |
Oops, something went wrong.