Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
7 / 7 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
TextFormatter | |
100.00% |
7 / 7 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
getLangCode | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
format | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Message; |
4 | |
5 | use Wikimedia\Message\ITextFormatter; |
6 | use Wikimedia\Message\MessageValue; |
7 | |
8 | /** |
9 | * The MediaWiki-specific implementation of ITextFormatter |
10 | */ |
11 | class TextFormatter implements ITextFormatter { |
12 | /** @var Converter */ |
13 | private $converter; |
14 | |
15 | /** @var string */ |
16 | private $langCode; |
17 | |
18 | /** @var string */ |
19 | private $format; |
20 | |
21 | /** |
22 | * Construct a TextFormatter. |
23 | * |
24 | * The type signature may change without notice as dependencies are added |
25 | * to the constructor. External callers should use |
26 | * MediaWikiServices::getMessageFormatterFactory() |
27 | * |
28 | * @internal |
29 | * @param string $langCode |
30 | * @param Converter $converter |
31 | * @param string $format |
32 | */ |
33 | public function __construct( |
34 | string $langCode, |
35 | Converter $converter, |
36 | string $format = Message::FORMAT_TEXT |
37 | ) { |
38 | $this->langCode = $langCode; |
39 | $this->converter = $converter; |
40 | $this->format = $format; |
41 | } |
42 | |
43 | public function getLangCode() { |
44 | return $this->langCode; |
45 | } |
46 | |
47 | public function format( MessageValue $mv ) { |
48 | $message = $this->converter->convertMessageValue( $mv ); |
49 | $message->inLanguage( $this->langCode ); |
50 | return $message->toString( $this->format ); |
51 | } |
52 | } |