/** * Get the key of the current client session. * * @return string Session key * * @throws Exception Throws if an error occurred. */ function getSessionKey() { // Return the key from the globals if set if (isset($GLOBALS['session_key'])) { return $GLOBALS['session_key']; } // Get the session cookie name $sessionCookieName = Registry::getValue('client.session.cookie.name')->getValue(); // Get the session key $sessionKey = CookieManager::getCookie($sessionCookieName); // Set the session key global $GLOBALS['session_key'] = $sessionKey; // Return the session key return $sessionKey; }
/** * Set the language tag cookie. * * @param string|null $langTag The language tag, or null to reset. * * @throws Exception Throws if the language tag is unknown or invalid. */ public static function setCookieLanguageTag($langTag) { // Make sure the tag is valid or null if ($langTag !== null && !static::isWithTag($langTag)) { throw new Exception('Invalid or unknown language tag.'); } // Set or reset the cookie if ($langTag !== null) { CookieManager::setCookie(static::LANGUAGE_COOKIE_NAME, $langTag, static::LANGUAGE_COOKIE_EXPIRE); } else { CookieManager::deleteCookie(static::LANGUAGE_COOKIE_NAME); } }