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 * @license GPL-2.0-or-later
4 * @file
5 */
6
7namespace MediaWiki\Storage;
8
9use ExternalStoreAccess;
10use MediaWiki\Config\ServiceOptions;
11use MediaWiki\MainConfigNames;
12use Wikimedia\ObjectCache\WANObjectCache;
13use Wikimedia\Rdbms\ILBFactory;
14
15/**
16 * Service for instantiating BlobStores
17 *
18 * This can be used to create BlobStore objects for other wikis.
19 *
20 * @since 1.31
21 */
22class BlobStoreFactory {
23
24    /**
25     * @var ILBFactory
26     */
27    private $lbFactory;
28
29    /**
30     * @var ExternalStoreAccess
31     */
32    private $extStoreAccess;
33
34    /**
35     * @var WANObjectCache
36     */
37    private $cache;
38
39    /**
40     * @var ServiceOptions
41     */
42    private $options;
43
44    /**
45     * @internal For use by ServiceWiring
46     */
47    public const CONSTRUCTOR_OPTIONS = [
48        MainConfigNames::CompressRevisions,
49        MainConfigNames::DefaultExternalStore,
50        MainConfigNames::LegacyEncoding,
51        MainConfigNames::RevisionCacheExpiry,
52    ];
53
54    public function __construct(
55        ILBFactory $lbFactory,
56        ExternalStoreAccess $extStoreAccess,
57        WANObjectCache $cache,
58        ServiceOptions $options
59    ) {
60        $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
61
62        $this->lbFactory = $lbFactory;
63        $this->extStoreAccess = $extStoreAccess;
64        $this->cache = $cache;
65        $this->options = $options;
66    }
67
68    /**
69     * @since 1.31
70     *
71     * @param bool|string $dbDomain The ID of the target wiki database. Use false for the local wiki.
72     *
73     * @return BlobStore
74     */
75    public function newBlobStore( $dbDomain = false ) {
76        return $this->newSqlBlobStore( $dbDomain );
77    }
78
79    /**
80     * @internal Please call newBlobStore and use the BlobStore interface.
81     *
82     * @param bool|string $dbDomain The ID of the target wiki database. Use false for the local wiki.
83     *
84     * @return SqlBlobStore
85     */
86    public function newSqlBlobStore( $dbDomain = false ) {
87        $lb = $this->lbFactory->getMainLB( $dbDomain );
88        $store = new SqlBlobStore(
89            $lb,
90            $this->extStoreAccess,
91            $this->cache,
92            $dbDomain
93        );
94
95        $store->setCompressBlobs( $this->options->get( MainConfigNames::CompressRevisions ) );
96        $store->setCacheExpiry( $this->options->get( MainConfigNames::RevisionCacheExpiry ) );
97        $store->setUseExternalStore(
98            $this->options->get( MainConfigNames::DefaultExternalStore ) !== false );
99
100        if ( $this->options->get( MainConfigNames::LegacyEncoding ) ) {
101            $store->setLegacyEncoding( $this->options->get( MainConfigNames::LegacyEncoding ) );
102        }
103
104        return $store;
105    }
106
107}