Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
InterwikiResolverFactory
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
1 / 1
 build
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3namespace CirrusSearch;
4
5use MediaWiki\Interwiki\InterwikiLookup;
6use MediaWiki\Registration\ExtensionRegistry;
7use Wikimedia\Http\MultiHttpClient;
8use Wikimedia\ObjectCache\WANObjectCache;
9
10/**
11 * Factory class used to create InterwikiResolver
12 */
13class InterwikiResolverFactory {
14    /**
15     * Based on config variables available in $config
16     * returns the approriate the InterwikiResolver
17     * implementation.
18     * Fallback to EmptyInterwikiResolver.
19     *
20     * @param SearchConfig $config
21     * @param WANObjectCache $wanCache Cache object for caching repeated requests
22     * @param InterwikiLookup $iwLookup
23     * @param ExtensionRegistry $extensionRegistry
24     * @param MultiHttpClient $client http client to fetch cirrus config
25     * @return InterwikiResolver
26     * @see CirrusSearchInterwikiResolverFactory::accepts()
27     * @see SiteMatrixInterwikiResolver::accepts()
28     */
29    public static function build(
30        SearchConfig $config,
31        WANObjectCache $wanCache,
32        InterwikiLookup $iwLookup,
33        ExtensionRegistry $extensionRegistry,
34        MultiHttpClient $client
35    ): InterwikiResolver {
36        if ( CirrusConfigInterwikiResolver::accepts( $config ) ) {
37            return new CirrusConfigInterwikiResolver( $config, $client, $wanCache, $iwLookup );
38        }
39        if ( SiteMatrixInterwikiResolver::accepts( $config, $extensionRegistry ) ) {
40            return new SiteMatrixInterwikiResolver( $config, $client, $wanCache, $iwLookup );
41        }
42        return new EmptyInterwikiResolver();
43    }
44}