mirror of
https://github.com/Respect/Validation.git
synced 2026-03-15 06:45:44 +01:00
32 lines
685 B
PHP
32 lines
685 B
PHP
<?php
|
|
|
|
/*
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Respect\Validation\Message\Translator;
|
|
|
|
use Respect\Validation\Message\Translator;
|
|
|
|
use function is_string;
|
|
|
|
final readonly class ArrayTranslator implements Translator
|
|
{
|
|
/** @param array<string, string> $messages */
|
|
public function __construct(
|
|
private array $messages,
|
|
) {
|
|
}
|
|
|
|
public function translate(string $message): string
|
|
{
|
|
if (isset($this->messages[$message]) && is_string($this->messages[$message])) {
|
|
return $this->messages[$message];
|
|
}
|
|
|
|
return $message;
|
|
}
|
|
}
|