From ac8cd6846df74e326d6e7e6b6b6d506819fe1e90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Thu, 26 Mar 2026 23:15:17 +0100 Subject: [PATCH] chore: Remove static vars in TemplateLayout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/private/TemplateLayout.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php index 88a2f5a89a8..63ae0cd6e60 100644 --- a/lib/private/TemplateLayout.php +++ b/lib/private/TemplateLayout.php @@ -43,9 +43,9 @@ use OCP\Template\ITemplateManager; use OCP\Util; class TemplateLayout { - private static string $versionHash = ''; + private string $versionHash = ''; /** @var string[] */ - private static array $cacheBusterCache = []; + private array $cacheBusterCache = []; public ?CSSResourceLocator $cssLocator = null; public ?JSResourceLocator $jsLocator = null; @@ -214,13 +214,13 @@ class TemplateLayout { $page->assign('enabledThemes', $themesService?->getEnabledThemes() ?? []); if ($this->config->getSystemValueBool('installed', false)) { - if (empty(self::$versionHash)) { + if (empty($this->versionHash)) { $v = $this->appManager->getAppInstalledVersions(true); $v['core'] = implode('.', $this->serverVersion->getVersion()); - self::$versionHash = substr(md5(implode(',', $v)), 0, 8); + $this->versionHash = substr(md5(implode(',', $v)), 0, 8); } } else { - self::$versionHash = md5('not installed'); + $this->versionHash = md5('not installed'); } // Add the js files @@ -250,7 +250,7 @@ class TemplateLayout { if (Server::get(ContentSecurityPolicyNonceManager::class)->browserSupportsCspV3()) { $page->assign('inline_ocjs', $config); } else { - $page->append('jsfiles', Server::get(IURLGenerator::class)->linkToRoute('core.OCJS.getConfig', ['v' => self::$versionHash])); + $page->append('jsfiles', Server::get(IURLGenerator::class)->linkToRoute('core.OCJS.getConfig', ['v' => $this->versionHash])); } } foreach ($jsFiles as $info) { @@ -283,7 +283,7 @@ class TemplateLayout { $page->assign('cssfiles', []); $page->assign('printcssfiles', []); - $this->initialState->provideInitialState('core', 'versionHash', self::$versionHash); + $this->initialState->provideInitialState('core', 'versionHash', $this->versionHash); foreach ($cssFiles as $info) { $web = $info[1]; $file = $info[2]; @@ -323,7 +323,7 @@ class TemplateLayout { if ($this->config->getSystemValueBool('installed', false) === false) { // if not installed just return the version hash - return '?v=' . self::$versionHash; + return '?v=' . $this->versionHash; } $hash = false; @@ -337,7 +337,7 @@ class TemplateLayout { } // As a last resort we use the server version hash if ($hash === false) { - $hash = self::$versionHash; + $hash = $this->versionHash; } // The theming app is force-enabled thus the cache buster is always available @@ -347,7 +347,7 @@ class TemplateLayout { } private function getVersionHashByPath(string $path): string|false { - if (array_key_exists($path, self::$cacheBusterCache) === false) { + if (array_key_exists($path, $this->cacheBusterCache) === false) { // Not yet cached, so lets find the cache buster string $appId = $this->getAppNamefromPath($path); if ($appId === false) { @@ -357,20 +357,20 @@ class TemplateLayout { if ($appId === 'core') { // core is not a real app but the server itself - $hash = self::$versionHash; + $hash = $this->versionHash; } else { $appVersion = $this->appManager->getAppVersion($appId); // For shipped apps the app version is not a single source of truth, we rather also need to consider the Nextcloud version if ($this->appManager->isShipped($appId)) { - $appVersion .= '-' . self::$versionHash; + $appVersion .= '-' . $this->versionHash; } $hash = substr(md5($appVersion), 0, 8); } - self::$cacheBusterCache[$path] = $hash; + $this->cacheBusterCache[$path] = $hash; } - return self::$cacheBusterCache[$path]; + return $this->cacheBusterCache[$path]; } private function findStylesheetFiles(array $styles): array {