Avoid using deprecated phpredis::delete() alias
[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 MediaWiki\Config\ServiceOptions;
24 use WANObjectCache;
25 use Wikimedia\Rdbms\ILBFactory;
26 use ExternalStoreAccess;
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 ExternalStoreAccess
44 */
45 private $extStoreAccess;
46
47 /**
48 * @var WANObjectCache
49 */
50 private $cache;
51
52 /**
53 * @var ServiceOptions
54 */
55 private $options;
56
57 /**
58 * @var array
59 * @since 1.34
60 */
61 public const CONSTRUCTOR_OPTIONS = [
62 'CompressRevisions',
63 'DefaultExternalStore',
64 'LegacyEncoding',
65 'RevisionCacheExpiry',
66 ];
67
68 public function __construct(
69 ILBFactory $lbFactory,
70 ExternalStoreAccess $extStoreAccess,
71 WANObjectCache $cache,
72 ServiceOptions $options
73 ) {
74 $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
75
76 $this->lbFactory = $lbFactory;
77 $this->extStoreAccess = $extStoreAccess;
78 $this->cache = $cache;
79 $this->options = $options;
80 }
81
82 /**
83 * @since 1.31
84 *
85 * @param bool|string $dbDomain The ID of the target wiki database. Use false for the local wiki.
86 *
87 * @return BlobStore
88 */
89 public function newBlobStore( $dbDomain = false ) {
90 return $this->newSqlBlobStore( $dbDomain );
91 }
92
93 /**
94 * @internal Please call newBlobStore and use the BlobStore interface.
95 *
96 * @param bool|string $dbDomain The ID of the target wiki database. Use false for the local wiki.
97 *
98 * @return SqlBlobStore
99 */
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
107 );
108
109 $store->setCompressBlobs( $this->options->get( 'CompressRevisions' ) );
110 $store->setCacheExpiry( $this->options->get( 'RevisionCacheExpiry' ) );
111 $store->setUseExternalStore( $this->options->get( 'DefaultExternalStore' ) !== false );
112
113 if ( $this->options->get( 'LegacyEncoding' ) ) {
114 $store->setLegacyEncoding( $this->options->get( 'LegacyEncoding' ) );
115 }
116
117 return $store;
118 }
119
120 }