Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
InterwikiResolverFactory
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 newFactory
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getResolver
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3namespace CirrusSearch;
4
5use BagOStuff;
6use MediaWiki\Interwiki\InterwikiLookup;
7use WANObjectCache;
8
9/**
10 * Factory class used to create InterwikiResolver
11 */
12class InterwikiResolverFactory {
13    /**
14     * @const string service name used in MediaWikiServices
15     */
16    public const SERVICE = 'CirrusSearchInterwikiResolverFactory';
17
18    /**
19     * @return InterwikiResolverFactory
20     */
21    public static function newFactory() {
22        return new InterwikiResolverFactory();
23    }
24
25    /**
26     * Based on config variables available in $config
27     * returns the approriate the InterwikiResolver
28     * implementation.
29     * Fallback to EmptyInterwikiResolver.
30     *
31     * @param SearchConfig $config
32     * @param \MultiHttpClient|null $client http client to fetch cirrus config
33     * @param WANObjectCache|null $wanCache Cache object for caching repeated requests
34     * @param BagOStuff|null $srvCache Local server cache object for caching repeated requests
35     * @param InterwikiLookup|null $iwLookup
36     * @return InterwikiResolver
37     * @throws \Exception
38     * @see CirrusSearchInterwikiResolverFactory::accepts()
39     * @see SiteMatrixInterwikiResolver::accepts()
40     */
41    public function getResolver(
42        SearchConfig $config,
43        \MultiHttpClient $client = null,
44        WANObjectCache $wanCache = null,
45        BagOStuff $srvCache = null,
46        InterwikiLookup $iwLookup = null
47    ) {
48        if ( CirrusConfigInterwikiResolver::accepts( $config ) ) {
49            return new CirrusConfigInterwikiResolver( $config, $client, $wanCache, $srvCache, $iwLookup );
50        }
51        if ( SiteMatrixInterwikiResolver::accepts( $config ) ) {
52            return new SiteMatrixInterwikiResolver( $config, $client, $wanCache, $srvCache );
53        }
54        return new EmptyInterwikiResolver();
55    }
56}