Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
95.00% covered (success)
95.00%
19 / 20
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
BlobStoreFactory
95.00% covered (success)
95.00%
19 / 20
66.67% covered (warning)
66.67%
2 / 3
4
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 newBlobStore
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 newSqlBlobStore
92.86% covered (success)
92.86%
13 / 14
0.00% covered (danger)
0.00%
0 / 1
2.00
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
21namespace MediaWiki\Storage;
22
23use ExternalStoreAccess;
24use MediaWiki\Config\ServiceOptions;
25use MediaWiki\MainConfigNames;
26use WANObjectCache;
27use Wikimedia\Rdbms\ILBFactory;
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 */
36class 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     * @internal For use by ServiceWiring
60     */
61    public const CONSTRUCTOR_OPTIONS = [
62        MainConfigNames::CompressRevisions,
63        MainConfigNames::DefaultExternalStore,
64        MainConfigNames::LegacyEncoding,
65        MainConfigNames::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( MainConfigNames::CompressRevisions ) );
110        $store->setCacheExpiry( $this->options->get( MainConfigNames::RevisionCacheExpiry ) );
111        $store->setUseExternalStore(
112            $this->options->get( MainConfigNames::DefaultExternalStore ) !== false );
113
114        if ( $this->options->get( MainConfigNames::LegacyEncoding ) ) {
115            $store->setLegacyEncoding( $this->options->get( MainConfigNames::LegacyEncoding ) );
116        }
117
118        return $store;
119    }
120
121}