wiki.techinc.nl/includes/Message/MessageFormatterFactory.php
Petr Pchelko 7f643f2ab6 UserNameUtils: use ITextFormatter instead of MessageLocalizer
Bug: T249045
Change-Id: Ica1e1e4788d4b9f9dfcf9f8c8b4136147d92b32e
2020-04-13 09:28:02 -07:00

41 lines
1 KiB
PHP

<?php
namespace MediaWiki\Message;
use Message;
use Wikimedia\Message\IMessageFormatterFactory;
use Wikimedia\Message\ITextFormatter;
/**
* The MediaWiki-specific implementation of IMessageFormatterFactory
*/
class MessageFormatterFactory implements IMessageFormatterFactory {
/** @var string */
private $format;
/** @var array */
private $textFormatters = [];
/**
* Required parameters may be added to this function without deprecation.
* External callers should use MediaWikiServices::getMessageFormatterFactory().
*
* @param string $format which if the Message::FORMAT_* to use in the formatters.
* @internal
*/
public function __construct( string $format = Message::FORMAT_TEXT ) {
$this->format = $format;
}
/**
* @inheritDoc
*/
public function getTextFormatter( $langCode ): ITextFormatter {
if ( !isset( $this->textFormatters[$langCode] ) ) {
$this->textFormatters[$langCode] = new TextFormatter(
$langCode, new Converter(), $this->format );
}
return $this->textFormatters[$langCode];
}
}