2declare( strict_types = 1 );
4namespace MediaWiki\Extension\Translate\FileFormatSupport;
7use InvalidArgumentException;
8use Wikimedia\ObjectFactory\ObjectFactory;
23 private const FORMATS = [
24 'Amd' => AmdFormat::class,
25 'AndroidXml' => AndroidXmlFormat::class,
26 'Apple' => AppleFormat::class,
27 'Dtd' => DtdFormat::class,
28 'FlatPhp' => FlatPhpFormat::class,
29 'Fluent' => FluentFormat::class,
30 'Gettext' => GettextFormat::class,
31 'Ini' => IniFormat::class,
32 'Java' => JavaFormat::class,
33 'Json' => JsonFormat::class,
34 'Yaml' => YamlFormat::class
37 public function __construct(
38 private readonly ObjectFactory $objectFactory,
50 if ( !isset( self::FORMATS[$format] ) ) {
51 throw new InvalidArgumentException(
52 "FileFormatSupport: Unknown file format '$format' specified for group '{$group->getId()}'"
56 $spec = self::FORMATS[$format];
57 if ( is_string( $spec ) ) {
58 $spec = [
'class' => $spec ];
62 $spec[
'args'][] = $group;
64 return $this->objectFactory->createObject( $spec );
68 if ( !class_exists( $class ) ) {
69 throw new InvalidArgumentException(
70 "Could not find FileFormat class '$class' specified for group '{$group->getId()}'."
74 return new $class( $group );
77 public function getClassname(
string $format ): string {
78 if ( !isset( self::FORMATS[$format] ) ) {
79 throw new InvalidArgumentException(
"Unknown format $format" );
82 return self::FORMATS[$format];
This class implements default behavior for file based message groups.