wiki.techinc.nl/includes/Storage/BlobStoreFactory.php
Aryeh Gregor 18ec468633 Don't pass Config to service constructors
We don't want to depend on the entire site configuration when we only
need a few specific settings.

This change additionally means that these services no longer see a live
version of the settings, but rather a copy. This means in tests you
really do have to call overrideMwServices() if you want services to pick
up your config changes.

ResourceLoader and SearchEngineConfig will need more work to port,
because they expose their member Config in a getter, and the getter is
actually used.

Parser and NamespaceInfo are also relatively complicated, so I split
them into separate patches.

Tested with 100% code coverage. \o/

Depends-On: If6534b18f6657ec1aba7327463f2661037f995b3
Change-Id: I1a3f358e8659b49de4502dc8216ecb6f35f4e02a
2019-05-02 11:33:56 +03:00

121 lines
2.8 KiB
PHP

<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
*/
namespace MediaWiki\Storage;
use Language;
use MediaWiki\Config\ServiceOptions;
use WANObjectCache;
use Wikimedia\Rdbms\LBFactory;
/**
* Service for instantiating BlobStores
*
* This can be used to create BlobStore objects for other wikis.
*
* @since 1.31
*/
class BlobStoreFactory {
/**
* @var LBFactory
*/
private $lbFactory;
/**
* @var WANObjectCache
*/
private $cache;
/**
* @var ServiceOptions
*/
private $options;
/**
* @var Language
*/
private $contLang;
/**
* TODO Make this a const when HHVM support is dropped (T192166)
*
* @var array
* @since 1.34
*/
public static $constructorOptions = [
'CompressRevisions',
'DefaultExternalStore',
'LegacyEncoding',
'RevisionCacheExpiry',
];
public function __construct(
LBFactory $lbFactory,
WANObjectCache $cache,
ServiceOptions $options,
Language $contLang
) {
$options->assertRequiredOptions( self::$constructorOptions );
$this->lbFactory = $lbFactory;
$this->cache = $cache;
$this->options = $options;
$this->contLang = $contLang;
}
/**
* @since 1.31
*
* @param bool|string $wikiId The ID of the target wiki database. Use false for the local wiki.
*
* @return BlobStore
*/
public function newBlobStore( $wikiId = false ) {
return $this->newSqlBlobStore( $wikiId );
}
/**
* @internal Please call newBlobStore and use the BlobStore interface.
*
* @param bool|string $wikiId The ID of the target wiki database. Use false for the local wiki.
*
* @return SqlBlobStore
*/
public function newSqlBlobStore( $wikiId = false ) {
$lb = $this->lbFactory->getMainLB( $wikiId );
$store = new SqlBlobStore(
$lb,
$this->cache,
$wikiId
);
$store->setCompressBlobs( $this->options->get( 'CompressRevisions' ) );
$store->setCacheExpiry( $this->options->get( 'RevisionCacheExpiry' ) );
$store->setUseExternalStore( $this->options->get( 'DefaultExternalStore' ) !== false );
if ( $this->options->get( 'LegacyEncoding' ) ) {
$store->setLegacyEncoding( $this->options->get( 'LegacyEncoding' ), $this->contLang );
}
return $store;
}
}