Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
93.75% covered (success)
93.75%
15 / 16
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
BlobStoreFactory
93.75% covered (success)
93.75%
15 / 16
66.67% covered (warning)
66.67%
2 / 3
4.00
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
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 MediaWiki\Config\ServiceOptions;
10use MediaWiki\ExternalStore\ExternalStoreAccess;
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     * @internal For use by ServiceWiring
26     */
27    public const CONSTRUCTOR_OPTIONS = [
28        MainConfigNames::CompressRevisions,
29        MainConfigNames::DefaultExternalStore,
30        MainConfigNames::LegacyEncoding,
31        MainConfigNames::RevisionCacheExpiry,
32    ];
33
34    public function __construct(
35        private readonly ILBFactory $lbFactory,
36        private readonly ExternalStoreAccess $extStoreAccess,
37        private readonly WANObjectCache $cache,
38        private readonly ServiceOptions $options,
39    ) {
40        $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
41    }
42
43    /**
44     * @since 1.31
45     *
46     * @param bool|string $dbDomain The ID of the target wiki database. Use false for the local wiki.
47     *
48     * @return BlobStore
49     */
50    public function newBlobStore( $dbDomain = false ) {
51        return $this->newSqlBlobStore( $dbDomain );
52    }
53
54    /**
55     * @internal Please call newBlobStore and use the BlobStore interface.
56     *
57     * @param bool|string $dbDomain The ID of the target wiki database. Use false for the local wiki.
58     *
59     * @return SqlBlobStore
60     */
61    public function newSqlBlobStore( $dbDomain = false ) {
62        $lb = $this->lbFactory->getMainLB( $dbDomain );
63        $store = new SqlBlobStore(
64            $lb,
65            $this->extStoreAccess,
66            $this->cache,
67            $dbDomain
68        );
69
70        $store->setCompressBlobs( $this->options->get( MainConfigNames::CompressRevisions ) );
71        $store->setCacheExpiry( $this->options->get( MainConfigNames::RevisionCacheExpiry ) );
72        $store->setUseExternalStore(
73            $this->options->get( MainConfigNames::DefaultExternalStore ) !== false );
74
75        if ( $this->options->get( MainConfigNames::LegacyEncoding ) ) {
76            $store->setLegacyEncoding( $this->options->get( MainConfigNames::LegacyEncoding ) );
77        }
78
79        return $store;
80    }
81
82}