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