0 follower

Final Class Yiisoft\Translator\Message\Php\MessageSource

InheritanceYiisoft\Translator\Message\Php\MessageSource
ImplementsYiisoft\Translator\MessageReaderInterface, Yiisoft\Translator\MessageWriterInterface

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( string $path )
$path string

                public function __construct(private string $path)
{
}

            
getMessage() public method

public string|null getMessage ( string $id, string $category, string $locale, array $parameters = [] )
$id string
$category string
$locale string
$parameters array

                public function getMessage(string $id, string $category, string $locale, array $parameters = []): ?string
{
    if (!isset($this->messages[$category][$locale])) {
        $this->read($category, $locale);
    }
    return $this->messages[$category][$locale][$id] ?? null;
}

            
getMessages() public method

public array getMessages ( string $category, string $locale )
$category string
$locale string

                public function getMessages(string $category, string $locale): array
{
    if (!isset($this->messages[$category][$locale])) {
        $this->read($category, $locale);
    }
    $messages = $this->messages[$category][$locale] ?? [];
    foreach ($messages as &$message) {
        $message = ['message' => $message];
    }
    /** @psalm-var array<string, array<string, string>> $messages */
    return $messages;
}

            
write() public method

public void write ( string $category, string $locale, array $messages )
$category string
$locale string
$messages array

                public function write(string $category, string $locale, array $messages): void
{
    $content = $this->generateMessagesFileContent($messages);
    $path = $this->getFilePath($category, $locale, true);
    if (file_put_contents($path, $content, LOCK_EX) === false) {
        throw new RuntimeException('Can not write to ' . $path);
    }
}