From: Joshua Rüsweg Date: Sun, 9 Jul 2017 14:12:37 +0000 (+0200) Subject: Add method to cache the replacements for each object X-Git-Tag: 3.1.0_Alpha_1~289 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=cc224811a07f1e5374f15facee07cfc8cdedc82d;p=GitHub%2FWoltLab%2FWCF.git Add method to cache the replacements for each object See #2315 --- diff --git a/wcfsetup/install/files/lib/data/user/trophy/UserTrophy.class.php b/wcfsetup/install/files/lib/data/user/trophy/UserTrophy.class.php index 6dcc147497..7bd6bb488e 100644 --- a/wcfsetup/install/files/lib/data/user/trophy/UserTrophy.class.php +++ b/wcfsetup/install/files/lib/data/user/trophy/UserTrophy.class.php @@ -1,10 +1,10 @@ getTrophy()->getDescription(); } - $replacements = [ - '{$username}' => $this->getUserProfile()->username - ]; - - $parameters = ['replacements' => $replacements]; - - EventHandler::getInstance()->fireAction($this, 'getDescription', $parameters); - - $replacements = $parameters['replacements']; - - return nl2br(StringUtil::encodeHTML(strtr($this->description, $replacements))); + return nl2br(StringUtil::encodeHTML(strtr($this->description, $this->getReplacements()))); } /** @@ -98,4 +94,25 @@ class UserTrophy extends DatabaseObject { // @TODO check user option canViewTrophies return true; } + + /** + * Returns an array with replacements for the trophy. + * + * @return string[] + */ + protected function getReplacements() { + if ($this->replacements == null) { + $replacements = [ + '{$username}' => $this->getUserProfile()->username + ]; + + $parameters = ['replacements' => $replacements]; + + EventHandler::getInstance()->fireAction($this, 'getDescription', $parameters); + + $this->replacements = $parameters['replacements']; + } + + return $this->replacements; + } } diff --git a/wcfsetup/install/files/lib/data/user/trophy/UserTrophyAction.class.php b/wcfsetup/install/files/lib/data/user/trophy/UserTrophyAction.class.php index 16f0092edd..c6fc1d0003 100644 --- a/wcfsetup/install/files/lib/data/user/trophy/UserTrophyAction.class.php +++ b/wcfsetup/install/files/lib/data/user/trophy/UserTrophyAction.class.php @@ -1,7 +1,7 @@