private function interpolateString($message, array $context = [])
    {
        // Build a replacement array with braces around the context keys.
        $replace = [];
        foreach ($context as $key => $value) {
            // Check that the value can be cast to string.
            if (!is_array($value) && (!is_object($value) || method_exists($value, '__toString'))) {
                $replace['{' . $key . '}'] = $value;
            }
        }

        // Interpolate replacement values into the message.
        $result = strtr($message, $replace);
        
        if (is_string($result)) {
            return $result;
        }
        
        /* If something went wrong, return the original message (with a
         * warning).  */
        return sprintf(
            '%s (WARNING: Unable to interpolate the context values into the message. %s).',
            $message,
            var_export($replace, true)
        );
    }