From: Tim Düsterhus Date: Wed, 14 Oct 2020 12:16:01 +0000 (+0200) Subject: Deprecate the 'environment' session variables X-Git-Tag: 5.4.0_Alpha_1~724^2~10^2~12 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=ee5b8b7ff2f2e73a644334df6cb9b43c9fe6e7e4;p=GitHub%2FWoltLab%2FWCF.git Deprecate the 'environment' session variables --- diff --git a/wcfsetup/install/files/lib/system/session/SessionHandler.class.php b/wcfsetup/install/files/lib/system/session/SessionHandler.class.php index 30381b5629..3d80654b58 100644 --- a/wcfsetup/install/files/lib/system/session/SessionHandler.class.php +++ b/wcfsetup/install/files/lib/system/session/SessionHandler.class.php @@ -29,12 +29,7 @@ use wcf\util\UserUtil; * @package WoltLabSuite\Core\System\Session * * @property-read string $sessionID unique textual identifier of the session - * @property-read integer|null $userID id of the user the session belongs to or `null` if the acp session belongs to a guest - * @property-read string $ipAddress id of the user whom the session belongs to - * @property-read string $userAgent user agent of the user whom the session belongs to - * @property-read integer $lastActivityTime timestamp at which the latest activity occurred - * @property-read string $requestURI uri of the latest request - * @property-read string $requestMethod used request method of the latest request (`GET`, `POST`) + * @property-read integer|null $userID id of the user the session belongs to or `null` if the session belongs to a guest * @property-read integer|null $pageID id of the latest page visited * @property-read integer|null $pageObjectID id of the object the latest page visited belongs to * @property-read integer|null $parentPageID id of the parent page of latest page visited @@ -53,13 +48,7 @@ final class SessionHandler extends SingletonFactory { * @var boolean */ protected $disableTracking = false; - - /** - * various environment variables - * @var array - */ - protected $environment = []; - + /** * group data and permissions * @var mixed[][] @@ -155,8 +144,18 @@ final class SessionHandler extends SingletonFactory { } // TODO: pageID, pageObjectID, parentPageID, parentPageObjectID - if (array_key_exists($key, $this->environment)) { - return $this->environment[$key]; + /** @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) : '', + 'spiderID' => $this->getSpiderID(UserUtil::getUserAgent()), + 'lastActivityTime' => TIME_NOW, + ]; + + if (array_key_exists($key, $environment)) { + return $environment[$key]; } return null; @@ -263,9 +262,6 @@ final class SessionHandler extends SingletonFactory { $this->languageID = ($this->getVar('languageID') === null) ? $this->user->languageID : $this->getVar('languageID'); $this->styleID = ($this->getVar('styleID') === null) ? $this->user->styleID : $this->getVar('styleID'); - // init environment variables - $this->initEnvironment(); - // https://github.com/WoltLab/WCF/issues/2568 if ($this->getVar('__wcfIsFirstVisit') === true) { $this->firstVisit = true; @@ -273,20 +269,6 @@ final class SessionHandler extends SingletonFactory { } } - /** - * Initializes environment variables. - */ - protected function initEnvironment() { - $this->environment = [ - 'ipAddress' => UserUtil::getIpAddress(), - 'userAgent' => UserUtil::getUserAgent(), - 'requestURI' => UserUtil::getRequestURI(), - 'requestMethod' => !empty($_SERVER['REQUEST_METHOD']) ? substr($_SERVER['REQUEST_METHOD'], 0, 7) : '', - 'spiderID' => $this->getSpiderID(UserUtil::getUserAgent()), - 'lastActivityTime' => TIME_NOW, - ]; - } - /** * Disables update on shutdown. */