Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
11 / 11 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
LexemeLanguageNameLookupFactory | |
100.00% |
11 / 11 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getForLanguageCodeAndMessageLocalizer | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
getForContextSource | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | declare( strict_types = 1 ); |
4 | |
5 | namespace Wikibase\Lexeme\MediaWiki\Content; |
6 | |
7 | use MediaWiki\Context\IContextSource; |
8 | use MessageLocalizer; |
9 | use Wikibase\Lib\LanguageNameLookupFactory; |
10 | |
11 | /** |
12 | * @license GPL-2.0-or-later |
13 | */ |
14 | class LexemeLanguageNameLookupFactory { |
15 | |
16 | /** @var LanguageNameLookupFactory */ |
17 | private $languageNameLookupFactory; |
18 | |
19 | /** @var string[] */ |
20 | private $additionalLanguages; |
21 | |
22 | public function __construct( |
23 | LanguageNameLookupFactory $languageNameLookupFactory, |
24 | array $additionalLanguages |
25 | ) { |
26 | $this->languageNameLookupFactory = $languageNameLookupFactory; |
27 | $this->additionalLanguages = $additionalLanguages; |
28 | } |
29 | |
30 | public function getForLanguageCodeAndMessageLocalizer( |
31 | string $languageCode, |
32 | MessageLocalizer $messageLocalizer |
33 | ): LexemeLanguageNameLookup { |
34 | return new LexemeLanguageNameLookup( |
35 | $messageLocalizer, |
36 | $this->additionalLanguages, |
37 | $this->languageNameLookupFactory->getForLanguageCode( $languageCode ) |
38 | ); |
39 | } |
40 | |
41 | public function getForContextSource( |
42 | IContextSource $context |
43 | ): LexemeLanguageNameLookup { |
44 | return $this->getForLanguageCodeAndMessageLocalizer( |
45 | $context->getLanguage()->getCode(), |
46 | $context |
47 | ); |
48 | } |
49 | |
50 | } |