HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux ns3133907 6.8.0-86-generic #87-Ubuntu SMP PREEMPT_DYNAMIC Mon Sep 22 18:03:36 UTC 2025 x86_64
User: cssnetorguk (1024)
PHP: 8.2.28
Disabled: NONE
Upload Files
File: //proc/self/root/usr/share/php/PhpMyAdmin/MoTranslator/Cache/InMemoryCache.php
<?php

declare(strict_types=1);

namespace PhpMyAdmin\MoTranslator\Cache;

use PhpMyAdmin\MoTranslator\MoParser;

use function array_key_exists;

final class InMemoryCache implements CacheInterface, GetAllInterface
{
    /** @var array<string, string> */
    private $cache;

    public function __construct(MoParser $parser)
    {
        $this->cache = [];
        $parser->parseIntoCache($this);
    }

    public function get(string $msgid): string
    {
        return array_key_exists($msgid, $this->cache) ? $this->cache[$msgid] : $msgid;
    }

    public function set(string $msgid, string $msgstr): void
    {
        $this->cache[$msgid] = $msgstr;
    }

    public function has(string $msgid): bool
    {
        return array_key_exists($msgid, $this->cache);
    }

    public function setAll(array $translations): void
    {
        $this->cache = $translations;
    }

    /**
     * @inheritDoc
     */
    public function getAll(): array
    {
        return $this->cache;
    }
}