Services: Convert BlobStoreFactory's static to a const now HHVM is gone
[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 * @var array
65 * @since 1.34
66 */
67 public const CONSTRUCTOR_OPTIONS = [
68 'CompressRevisions',
69 'DefaultExternalStore',
70 'LegacyEncoding',
71 'RevisionCacheExpiry',
72 ];
73
74 public function __construct(
75 ILBFactory $lbFactory,
76 ExternalStoreAccess $extStoreAccess,
77 WANObjectCache $cache,
78 ServiceOptions $options,
79 Language $contLang
80 ) {
81 $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
82
83 $this->lbFactory = $lbFactory;
84 $this->extStoreAccess = $extStoreAccess;
85 $this->cache = $cache;
86 $this->options = $options;
87 $this->contLang = $contLang;
88 }
89
90 /**
91 * @since 1.31
92 *
93 * @param bool|string $dbDomain The ID of the target wiki database. Use false for the local wiki.
94 *
95 * @return BlobStore
96 */
97 public function newBlobStore( $dbDomain = false ) {
98 return $this->newSqlBlobStore( $dbDomain );
99 }
100
101 /**
102 * @internal Please call newBlobStore and use the BlobStore interface.
103 *
104 * @param bool|string $dbDomain The ID of the target wiki database. Use false for the local wiki.
105 *
106 * @return SqlBlobStore
107 */
108 public function newSqlBlobStore( $dbDomain = false ) {
109 $lb = $this->lbFactory->getMainLB( $dbDomain );
110 $store = new SqlBlobStore(
111 $lb,
112 $this->extStoreAccess,
113 $this->cache,
114 $dbDomain
115 );
116
117 $store->setCompressBlobs( $this->options->get( 'CompressRevisions' ) );
118 $store->setCacheExpiry( $this->options->get( 'RevisionCacheExpiry' ) );
119 $store->setUseExternalStore( $this->options->get( 'DefaultExternalStore' ) !== false );
120
121 if ( $this->options->get( 'LegacyEncoding' ) ) {
122 $store->setLegacyEncoding( $this->options->get( 'LegacyEncoding' ), $this->contLang );
123 }
124
125 return $store;
126 }
127
128 }