localisation: Inject 'directory' option to LCStore classes
[lhc/web/wiklou.git] / includes / cache / localisation / LocalisationCache.php
index db0f380..788eec3 100644 (file)
@@ -192,7 +192,11 @@ class LocalisationCache {
                global $wgCacheDirectory;
 
                $this->conf = $conf;
-               $storeConf = [];
+
+               $directory = !empty( $conf['storeDirectory'] ) ? $conf['storeDirectory'] : $wgCacheDirectory;
+               $storeArg = [];
+               $storeArg['directory'] = $directory;
+
                if ( !empty( $conf['storeClass'] ) ) {
                        $storeClass = $conf['storeClass'];
                } else {
@@ -203,20 +207,17 @@ class LocalisationCache {
                                        break;
                                case 'db':
                                        $storeClass = LCStoreDB::class;
-                                       $storeConf['server'] = $conf['storeServer'] ?? [];
+                                       $storeArg['server'] = $conf['storeServer'] ?? [];
                                        break;
                                case 'array':
                                        $storeClass = LCStoreStaticArray::class;
                                        break;
                                case 'detect':
-                                       if ( !empty( $conf['storeDirectory'] ) ) {
-                                               $storeClass = LCStoreCDB::class;
-                                       } elseif ( $wgCacheDirectory ) {
-                                               $storeConf['directory'] = $wgCacheDirectory;
+                                       if ( $directory ) {
                                                $storeClass = LCStoreCDB::class;
                                        } else {
                                                $storeClass = LCStoreDB::class;
-                                               $storeConf['server'] = $conf['storeServer'] ?? [];
+                                               $storeArg['server'] = $conf['storeServer'] ?? [];
                                        }
                                        break;
                                default:
@@ -227,11 +228,8 @@ class LocalisationCache {
                }
 
                wfDebugLog( 'caches', static::class . ": using store $storeClass" );
-               if ( !empty( $conf['storeDirectory'] ) ) {
-                       $storeConf['directory'] = $conf['storeDirectory'];
-               }
 
-               $this->store = new $storeClass( $storeConf );
+               $this->store = new $storeClass( $storeArg );
                foreach ( [ 'manualRecache', 'forceRecache' ] as $var ) {
                        if ( isset( $conf[$var] ) ) {
                                $this->$var = $conf[$var];