- function __construct( $conf ) {
- global $wgCacheDirectory;
-
- $this->conf = $conf;
- $this->logger = LoggerFactory::getInstance( 'localisation' );
-
- $directory = !empty( $conf['storeDirectory'] ) ? $conf['storeDirectory'] : $wgCacheDirectory;
- $storeArg = [];
- $storeArg['directory'] = $directory;
-
- if ( !empty( $conf['storeClass'] ) ) {
- $storeClass = $conf['storeClass'];
- } else {
- switch ( $conf['store'] ) {
- case 'files':
- case 'file':
- $storeClass = LCStoreCDB::class;
- break;
- case 'db':
- $storeClass = LCStoreDB::class;
- $storeArg['server'] = $conf['storeServer'] ?? [];
- break;
- case 'array':
- $storeClass = LCStoreStaticArray::class;
- break;
- case 'detect':
- if ( $directory ) {
- $storeClass = LCStoreCDB::class;
- } else {
- $storeClass = LCStoreDB::class;
- $storeArg['server'] = $conf['storeServer'] ?? [];
- }
- break;
- default:
- throw new MWException(
- 'Please set $wgLocalisationCacheConf[\'store\'] to something sensible.'
- );
- }
- }
- $this->logger->debug( static::class . ": using store $storeClass" );
-
- $this->store = new $storeClass( $storeArg );
- foreach ( [ 'manualRecache', 'forceRecache' ] as $var ) {
- if ( isset( $conf[$var] ) ) {
- $this->$var = $conf[$var];
- }
- }
+ function __construct(
+ ServiceOptions $options,
+ LCStore $store,
+ LoggerInterface $logger,
+ array $clearStoreCallbacks = []
+ ) {
+ $options->assertRequiredOptions( self::$constructorOptions );
+
+ $this->options = $options;
+ $this->store = $store;
+ $this->logger = $logger;
+ $this->clearStoreCallbacks = $clearStoreCallbacks;
+
+ // Keep this separate from $this->options so it can be mutable
+ $this->manualRecache = $options->get( 'manualRecache' );