Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
MessageFormatterFactory
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getTextFormatter
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace MediaWiki\Message;
4
5use Wikimedia\Message\IMessageFormatterFactory;
6use Wikimedia\Message\ITextFormatter;
7
8/**
9 * The MediaWiki-specific implementation of IMessageFormatterFactory
10 *
11 * To obtain an instance, use \MediaWiki\MediaWikiServices::getMessageFormatterFactory().
12 *
13 * @ingroup Language
14 */
15class MessageFormatterFactory implements IMessageFormatterFactory {
16
17    /** @var string */
18    private $format;
19
20    /** @var array */
21    private $textFormatters = [];
22
23    /**
24     * @internal For use by ServiceWiring only
25     * @param string $format which if the Message::FORMAT_* to use in the formatters.
26     */
27    public function __construct( string $format = Message::FORMAT_TEXT ) {
28        $this->format = $format;
29    }
30
31    /**
32     * @inheritDoc
33     */
34    public function getTextFormatter( string $langCode ): ITextFormatter {
35        if ( !isset( $this->textFormatters[$langCode] ) ) {
36            $this->textFormatters[$langCode] = new TextFormatter(
37                $langCode, $this->format );
38        }
39        return $this->textFormatters[$langCode];
40    }
41}