localisation: Inject 'directory' option to LCStore classes
authorTimo Tijhof <krinklemail@gmail.com>
Mon, 6 May 2019 21:52:52 +0000 (22:52 +0100)
committerKrinkle <krinklemail@gmail.com>
Tue, 14 May 2019 16:35:29 +0000 (16:35 +0000)
Avoid globals for this, inject them from the factory function instead.

Bug: T218207
Change-Id: Ia961e8e08dcf1ca154d74ea6a3dadd2d59c1299c

includes/cache/localisation/LCStoreCDB.php
includes/cache/localisation/LCStoreStaticArray.php
includes/cache/localisation/LocalisationCache.php

index 3455470..aad9439 100644 (file)
@@ -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 ) {
index d3504a8..5911656 100644 (file)
@@ -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 ) {
index 8a3a818..788eec3 100644 (file)
@@ -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 ) {