HEX
Server: LiteSpeed
System: Linux node612.namehero.net 4.18.0-553.121.1.lve.el8.x86_64 #1 SMP Thu Apr 30 16:40:41 UTC 2026 x86_64
User: dfwparty (1186)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: /home/dfwparty/public_html/wp-content/mu-plugins/wp-toolkit/Common/Services/I18n/IntlFormatter.php
<?php
// Copyright 1999-2026. WebPros International GmbH. All rights reserved.

namespace Webpros\WptkWpPlugin\WpToolkit\Common\Services\I18n;

final class IntlFormatter implements MessageFormatterInterface
{
    public function __construct()
    {
        if (!class_exists(\MessageFormatter::class)) {
            throw new \RuntimeException('The PHP intl extension is required to use the IntlFormatter.');
        }
    }

    /**
     * @param string $messageTemplate
     * @param string $localeCode
     *
     * @return string
     */
    public function format($messageTemplate, array $parameters, $localeCode)
    {
        static $cache = [];
        if (!$messageTemplate) {
            return '';
        }

        $formatter = null;
        if (!isset($cache[$localeCode][$messageTemplate])
            || !$formatter = $cache[$localeCode][$messageTemplate]
        ) {
            try {
                $cache[$localeCode][$messageTemplate] = $formatter = new \MessageFormatter($localeCode, $messageTemplate);
            } catch (\IntlException $e) {
                throw new \InvalidArgumentException(\sprintf('Invalid message format (error #%d): %s', intl_get_error_code(), intl_get_error_message()), 0, $e);
            }
        }

        $message = $messageTemplate;
        if ($formatter instanceof \MessageFormatter
            && ($message = $formatter->format($parameters)) === false
        ) {
            throw new \InvalidArgumentException(\sprintf('Unable to format message (error #%s): %s', $formatter->getErrorCode(), $formatter->getErrorMessage()));
        }

        return $message;
    }
}