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 'Gettext' => GettextFormat::class,
30 'Ini' => IniFormat::class,
31 'Java' => JavaFormat::class,
32 'Json' => JsonFormat::class,
33 'Yaml' => YamlFormat::class
35 private ObjectFactory $objectFactory;
37 public function __construct( ObjectFactory $objectFactory ) {
38 $this->objectFactory = $objectFactory;
49 if ( !isset( self::FORMATS[ $format ] ) ) {
50 throw new InvalidArgumentException(
51 "FileFormatSupport: Unknown file format '$format' specified for group '{$group->getId()}'"
55 $spec = self::FORMATS[ $format ];
56 if ( is_string( $spec ) ) {
57 $spec = [
'class' => $spec ];
61 $spec[
'args'][] = $group;
65 return $this->objectFactory->createObject( $spec );
69 if ( !class_exists( $class ) ) {
70 throw new InvalidArgumentException(
71 "Could not find FileFormat class '$class' specified for group '{$group->getId()}'."
75 return new $class( $group );
78 public function getClassname(
string $format ): string {
79 if ( !isset( self::FORMATS[ $format ] ) ) {
80 throw new InvalidArgumentException(
"Unknown format $format" );
83 return self::FORMATS[ $format ];