From: Timo Tijhof Date: Mon, 6 May 2019 21:52:52 +0000 (+0100) Subject: localisation: Inject 'directory' option to LCStore classes X-Git-Tag: 1.34.0-rc.0~1691^2 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=7630e2bdb470454cd88a55379b8b99eedd29a72c localisation: Inject 'directory' option to LCStore classes Avoid globals for this, inject them from the factory function instead. Bug: T218207 Change-Id: Ia961e8e08dcf1ca154d74ea6a3dadd2d59c1299c --- diff --git a/includes/cache/localisation/LCStoreCDB.php b/includes/cache/localisation/LCStoreCDB.php index 3455470752..aad9439ad6 100644 --- a/includes/cache/localisation/LCStoreCDB.php +++ b/includes/cache/localisation/LCStoreCDB.php @@ -42,13 +42,11 @@ class LCStoreCDB implements LCStore { /** @var string Current language code */ private $currentLang; - /** @var bool|string Cache directory. False if not set */ + /** @var string Cache directory */ private $directory; function __construct( $conf = [] ) { - global $wgCacheDirectory; - - $this->directory = $conf['directory'] ?? $wgCacheDirectory; + $this->directory = $conf['directory']; } public function get( $code, $key ) { diff --git a/includes/cache/localisation/LCStoreStaticArray.php b/includes/cache/localisation/LCStoreStaticArray.php index d3504a8fad..59116561c0 100644 --- a/includes/cache/localisation/LCStoreStaticArray.php +++ b/includes/cache/localisation/LCStoreStaticArray.php @@ -39,9 +39,7 @@ class LCStoreStaticArray implements LCStore { private $directory; public function __construct( $conf = [] ) { - global $wgCacheDirectory; - - $this->directory = $conf['directory'] ?? $wgCacheDirectory; + $this->directory = $conf['directory']; } public function startWrite( $code ) { diff --git a/includes/cache/localisation/LocalisationCache.php b/includes/cache/localisation/LocalisationCache.php index 8a3a818523..788eec345e 100644 --- a/includes/cache/localisation/LocalisationCache.php +++ b/includes/cache/localisation/LocalisationCache.php @@ -192,7 +192,11 @@ class LocalisationCache { global $wgCacheDirectory; $this->conf = $conf; + + $directory = !empty( $conf['storeDirectory'] ) ? $conf['storeDirectory'] : $wgCacheDirectory; $storeArg = []; + $storeArg['directory'] = $directory; + if ( !empty( $conf['storeClass'] ) ) { $storeClass = $conf['storeClass']; } else { @@ -209,10 +213,7 @@ class LocalisationCache { $storeClass = LCStoreStaticArray::class; break; case 'detect': - if ( !empty( $conf['storeDirectory'] ) ) { - $storeClass = LCStoreCDB::class; - } elseif ( $wgCacheDirectory ) { - $storeArg['directory'] = $wgCacheDirectory; + if ( $directory ) { $storeClass = LCStoreCDB::class; } else { $storeClass = LCStoreDB::class; @@ -227,9 +228,6 @@ class LocalisationCache { } wfDebugLog( 'caches', static::class . ": using store $storeClass" ); - if ( !empty( $conf['storeDirectory'] ) ) { - $storeArg['directory'] = $conf['storeDirectory']; - } $this->store = new $storeClass( $storeArg ); foreach ( [ 'manualRecache', 'forceRecache' ] as $var ) {