Merge "Fix SlotDiffRenderer documentation"
[lhc/web/wiklou.git] / includes / Storage / BlobStoreFactory.php
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.
7 *
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.
12 *
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
17 *
18 * @file
19 */
20
21 namespace MediaWiki\Storage;
22
23 use Language;
24 use MediaWiki\Config\ServiceOptions;
25 use WANObjectCache;
26 use Wikimedia\Rdbms\ILBFactory;
27 use ExternalStoreAccess;
28
29 /**
30 * Service for instantiating BlobStores
31 *
32 * This can be used to create BlobStore objects for other wikis.
33 *
34 * @since 1.31
35 */
36 class BlobStoreFactory {
37
38 /**
39 * @var ILBFactory
40 */
41 private $lbFactory;
42
43 /**
44 * @var ExternalStoreAccess
45 */
46 private $extStoreAccess;
47
48 /**
49 * @var WANObjectCache
50 */
51 private $cache;
52
53 /**
54 * @var ServiceOptions
55 */
56 private $options;
57
58 /**
59 * @var Language
60 */
61 private $contLang;
62
63 /**
64 * TODO Make this a const when HHVM support is dropped (T192166)
65 *
66 * @var array
67 * @since 1.34
68 */
69 public static $constructorOptions = [
70 'CompressRevisions',
71 'DefaultExternalStore',
72 'LegacyEncoding',
73 'RevisionCacheExpiry',
74 ];
75
76 public function __construct(
77 ILBFactory $lbFactory,
78 ExternalStoreAccess $extStoreAccess,
79 WANObjectCache $cache,
80 ServiceOptions $options,
81 Language $contLang
82 ) {
83 $options->assertRequiredOptions( self::$constructorOptions );
84
85 $this->lbFactory = $lbFactory;
86 $this->extStoreAccess = $extStoreAccess;
87 $this->cache = $cache;
88 $this->options = $options;
89 $this->contLang = $contLang;
90 }
91
92 /**
93 * @since 1.31
94 *
95 * @param bool|string $dbDomain The ID of the target wiki database. Use false for the local wiki.
96 *
97 * @return BlobStore
98 */
99 public function newBlobStore( $dbDomain = false ) {
100 return $this->newSqlBlobStore( $dbDomain );
101 }
102
103 /**
104 * @internal Please call newBlobStore and use the BlobStore interface.
105 *
106 * @param bool|string $dbDomain The ID of the target wiki database. Use false for the local wiki.
107 *
108 * @return SqlBlobStore
109 */
110 public function newSqlBlobStore( $dbDomain = false ) {
111 $lb = $this->lbFactory->getMainLB( $dbDomain );
112 $store = new SqlBlobStore(
113 $lb,
114 $this->extStoreAccess,
115 $this->cache,
116 $dbDomain
117 );
118
119 $store->setCompressBlobs( $this->options->get( 'CompressRevisions' ) );
120 $store->setCacheExpiry( $this->options->get( 'RevisionCacheExpiry' ) );
121 $store->setUseExternalStore( $this->options->get( 'DefaultExternalStore' ) !== false );
122
123 if ( $this->options->get( 'LegacyEncoding' ) ) {
124 $store->setLegacyEncoding( $this->options->get( 'LegacyEncoding' ), $this->contLang );
125 }
126
127 return $store;
128 }
129
130 }