ParsoidParser: Record ParserOptions watcher on ParserOutput object
[mediawiki.git] / includes / Storage / BlobStoreFactory.php
blob285c78c60e6233743466c63697b591fa571e31c6
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
18 * @file
21 namespace MediaWiki\Storage;
23 use ExternalStoreAccess;
24 use MediaWiki\Config\ServiceOptions;
25 use MediaWiki\MainConfigNames;
26 use WANObjectCache;
27 use Wikimedia\Rdbms\ILBFactory;
29 /**
30 * Service for instantiating BlobStores
32 * This can be used to create BlobStore objects for other wikis.
34 * @since 1.31
36 class BlobStoreFactory {
38 /**
39 * @var ILBFactory
41 private $lbFactory;
43 /**
44 * @var ExternalStoreAccess
46 private $extStoreAccess;
48 /**
49 * @var WANObjectCache
51 private $cache;
53 /**
54 * @var ServiceOptions
56 private $options;
58 /**
59 * @internal For use by ServiceWiring
61 public const CONSTRUCTOR_OPTIONS = [
62 MainConfigNames::CompressRevisions,
63 MainConfigNames::DefaultExternalStore,
64 MainConfigNames::LegacyEncoding,
65 MainConfigNames::RevisionCacheExpiry,
68 public function __construct(
69 ILBFactory $lbFactory,
70 ExternalStoreAccess $extStoreAccess,
71 WANObjectCache $cache,
72 ServiceOptions $options
73 ) {
74 $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
76 $this->lbFactory = $lbFactory;
77 $this->extStoreAccess = $extStoreAccess;
78 $this->cache = $cache;
79 $this->options = $options;
82 /**
83 * @since 1.31
85 * @param bool|string $dbDomain The ID of the target wiki database. Use false for the local wiki.
87 * @return BlobStore
89 public function newBlobStore( $dbDomain = false ) {
90 return $this->newSqlBlobStore( $dbDomain );
93 /**
94 * @internal Please call newBlobStore and use the BlobStore interface.
96 * @param bool|string $dbDomain The ID of the target wiki database. Use false for the local wiki.
98 * @return SqlBlobStore
100 public function newSqlBlobStore( $dbDomain = false ) {
101 $lb = $this->lbFactory->getMainLB( $dbDomain );
102 $store = new SqlBlobStore(
103 $lb,
104 $this->extStoreAccess,
105 $this->cache,
106 $dbDomain
109 $store->setCompressBlobs( $this->options->get( MainConfigNames::CompressRevisions ) );
110 $store->setCacheExpiry( $this->options->get( MainConfigNames::RevisionCacheExpiry ) );
111 $store->setUseExternalStore(
112 $this->options->get( MainConfigNames::DefaultExternalStore ) !== false );
114 if ( $this->options->get( MainConfigNames::LegacyEncoding ) ) {
115 $store->setLegacyEncoding( $this->options->get( MainConfigNames::LegacyEncoding ) );
118 return $store;