From 45de8a28cd45f1c4008d08a8d9abecbf9b525545 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 5 Aug 2018 15:56:21 +0200 Subject: [PATCH] Fix missing $_SESSION variable in src/App --- src/App.php | 10 +++------- src/Core/Session.php | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/App.php b/src/App.php index f583f151a6..d02ea73ca4 100644 --- a/src/App.php +++ b/src/App.php @@ -1399,16 +1399,12 @@ class App } } - if (!empty($_SESSION)) { - $user_theme = defaults($_SESSION, 'theme', $system_theme); - } else { - $user_theme = $system_theme; - } + $user_theme = Core\Session::get('theme', $system_theme); // Specific mobile theme override - if (($this->is_mobile || $this->is_tablet) && defaults($_SESSION, 'show-mobile', true)) { + if (($this->is_mobile || $this->is_tablet) && Core\Session::get('show-mobile', true)) { $system_mobile_theme = Config::get('system', 'mobile-theme'); - $user_mobile_theme = defaults($_SESSION, 'mobile-theme', $system_mobile_theme); + $user_mobile_theme = Core\Session::get('mobile-theme', $system_mobile_theme); // --- means same mobile theme as desktop if (!empty($user_mobile_theme) && $user_mobile_theme !== '---') { diff --git a/src/Core/Session.php b/src/Core/Session.php index b245c675b0..6d059eb4ef 100644 --- a/src/Core/Session.php +++ b/src/Core/Session.php @@ -45,9 +45,24 @@ class Session return isset($_SESSION[$name]); } - public static function get($name) + /** + * Retrieves a key from the session super global or the defaults if the key is missing or the value is falsy. + * + * Handle the case where session_start() hasn't been called and the super global isn't available. + * + * @param string $name + * @param mixed $defaults + * @return mixed + */ + public static function get($name, $defaults = null) { - return defaults($_SESSION, $name, null); + if (isset($_SESSION)) { + $return = defaults($_SESSION, $name, $defaults); + } else { + $return = $defaults; + } + + return $return; } public static function set($name, $value)