From 2b134240b80af4afd9bddef39b88f8c414d150d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 13 Dec 2016 11:17:58 +0100 Subject: [PATCH] Share code for session cache key calculation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- libraries/Util.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/libraries/Util.php b/libraries/Util.php index f2e67ac819..8e9562ef1f 100644 --- a/libraries/Util.php +++ b/libraries/Util.php @@ -2964,6 +2964,20 @@ class Util self::cacheUnset('is_grantuser'); } + /** + * Calculates session cache key + * + * @return string + */ + public static function cacheKey() + { + if (isset($GLOBALS['cfg']['Server']['user'])) { + return 'server_' . $GLOBALS['server'] . '_' . $GLOBALS['cfg']['Server']['user']; + } else { + return 'server_' . $GLOBALS['server']; + } + } + /** * Verifies if something is cached in the session * @@ -2973,7 +2987,7 @@ class Util */ public static function cacheExists($var) { - return isset($_SESSION['cache']['server_' . $GLOBALS['server'] . '_' . $GLOBALS['cfg']['Server']['user']][$var]); + return isset($_SESSION['cache'][self::cacheKey()][$var]); } /** @@ -2987,7 +3001,7 @@ class Util public static function cacheGet($var, $callback = null) { if (self::cacheExists($var)) { - return $_SESSION['cache']['server_' . $GLOBALS['server'] . '_' . $GLOBALS['cfg']['Server']['user']][$var]; + return $_SESSION['cache'][self::cacheKey()][$var]; } else { if ($callback) { $val = $callback(); @@ -3008,7 +3022,7 @@ class Util */ public static function cacheSet($var, $val = null) { - $_SESSION['cache']['server_' . $GLOBALS['server'] . '_' . $GLOBALS['cfg']['Server']['user']][$var] = $val; + $_SESSION['cache'][self::cacheKey()][$var] = $val; } /** @@ -3020,7 +3034,7 @@ class Util */ public static function cacheUnset($var) { - unset($_SESSION['cache']['server_' . $GLOBALS['server'] . '_' . $GLOBALS['cfg']['Server']['user']][$var]); + unset($_SESSION['cache'][self::cacheKey()][$var]); } /**