From 7105eac0425af4e2ea0335fcb0e8602fc0fbfa7e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Thu, 15 Oct 2020 11:27:43 +0200 Subject: [PATCH] Implement the (parent)?Page* values in SessionHandler::__get() And switch the whole method to a large switch statement. --- .../system/session/SessionHandler.class.php | 51 ++++++++++--------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/wcfsetup/install/files/lib/system/session/SessionHandler.class.php b/wcfsetup/install/files/lib/system/session/SessionHandler.class.php index 0af227d686..8f899fe1a4 100644 --- a/wcfsetup/install/files/lib/system/session/SessionHandler.class.php +++ b/wcfsetup/install/files/lib/system/session/SessionHandler.class.php @@ -136,31 +136,34 @@ final class SessionHandler extends SingletonFactory { * @return mixed */ public function __get($key) { - if ($key === 'sessionID') { - return $this->sessionID; - } - else if ($key === 'userID') { - return $this->user->userID; - } - else if ($key === 'spiderID') { - return $this->getSpiderID(UserUtil::getUserAgent()); - } - // TODO: pageID, pageObjectID, parentPageID, parentPageObjectID - - /** @deprecated 5.4 - These values can be retrieved more efficiently by directly using the methods in e.g. UserUtil. */ - $environment = [ - 'ipAddress' => UserUtil::getIpAddress(), - 'userAgent' => UserUtil::getUserAgent(), - 'requestURI' => UserUtil::getRequestURI(), - 'requestMethod' => !empty($_SERVER['REQUEST_METHOD']) ? substr($_SERVER['REQUEST_METHOD'], 0, 7) : '', - 'lastActivityTime' => TIME_NOW, - ]; - - if (array_key_exists($key, $environment)) { - return $environment[$key]; + switch ($key) { + case 'sessionID': + return $this->sessionID; + case 'userID': + return $this->user->userID; + case 'spiderID': + return $this->getSpiderID(UserUtil::getUserAgent()); + case 'pageID': + case 'pageObjectID': + case 'parentPageID': + case 'parentPageObjectID': + return $this->legacySession->{$key}; + + /** @deprecated 5.4 - The below values are deprecated. */ + case 'ipAddress': + return UserUtil::getIpAddress(); + case 'userAgent': + return UserUtil::getUserAgent(); + case 'requestURI': + return UserUtil::getRequestURI(); + case 'requestMethod': + return !empty($_SERVER['REQUEST_METHOD']) ? substr($_SERVER['REQUEST_METHOD'], 0, 7) : ''; + case 'lastActivityTime': + return TIME_NOW; + + default: + return null; } - - return null; } /** -- 2.20.1