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     * @param \ExtensionRegistry|null $extensionRegistry
37     * @return InterwikiResolver
38     * @throws \Exception
39     * @see CirrusSearchInterwikiResolverFactory::accepts()
40     * @see SiteMatrixInterwikiResolver::accepts()
41     */
42    public function getResolver(
43        SearchConfig $config,
44        \MultiHttpClient $client = null,
45        WANObjectCache $wanCache = null,
46        BagOStuff $srvCache = null,
47        InterwikiLookup $iwLookup = null,
48        \ExtensionRegistry $extensionRegistry = null
49    ) {
50        if ( CirrusConfigInterwikiResolver::accepts( $config ) ) {
51            return new CirrusConfigInterwikiResolver( $config, $client, $wanCache, $srvCache, $iwLookup );
52        }
53        if ( SiteMatrixInterwikiResolver::accepts( $config, $extensionRegistry ) ) {
54            return new SiteMatrixInterwikiResolver( $config, $client, $wanCache, $srvCache, $extensionRegistry );
55        }
56        return new EmptyInterwikiResolver();
57    }
58}