@@ -121,6 +121,17 @@ public function registerTypeArray($types) {
121121 }
122122 }
123123
124+ private function loadCustomDefinitions (string $ fileName , array &$ definitions ): void {
125+ if (file_exists ($ this ->customConfigDir . '/ ' . $ fileName )) {
126+ $ custom = json_decode (file_get_contents ($ this ->customConfigDir . '/ ' . $ fileName ), true );
127+ if (json_last_error () === JSON_ERROR_NONE ) {
128+ $ definitions = array_merge ($ definitions , $ custom );
129+ } else {
130+ $ this ->logger ->warning ('Failed to parse ' . $ fileName . ': ' . json_last_error_msg ());
131+ }
132+ }
133+ }
134+
124135 /**
125136 * Add the mimetype aliases if they are not yet present
126137 */
@@ -130,15 +141,7 @@ private function loadAliases() {
130141 }
131142
132143 $ this ->mimeTypeAlias = json_decode (file_get_contents ($ this ->defaultConfigDir . '/mimetypealiases.dist.json ' ), true );
133-
134- if (file_exists ($ this ->customConfigDir . '/ ' . self ::CUSTOM_MIMETYPEALIASES )) {
135- $ custom = json_decode (file_get_contents ($ this ->customConfigDir . '/ ' . self ::CUSTOM_MIMETYPEALIASES ), true );
136- if (json_last_error () === JSON_ERROR_NONE ) {
137- $ this ->mimeTypeAlias = array_merge ($ this ->mimeTypeAlias , $ custom );
138- } else {
139- $ this ->logger ->warning ('Failed to parse ' . self ::CUSTOM_MIMETYPEALIASES . ': ' . json_last_error_msg ());
140- }
141- }
144+ $ this ->loadCustomDefinitions (self ::CUSTOM_MIMETYPEALIASES , $ this ->mimeTypeAlias );
142145 }
143146
144147 /**
@@ -164,16 +167,7 @@ private function loadMappings() {
164167 }
165168
166169 $ mimetypeMapping = json_decode (file_get_contents ($ this ->defaultConfigDir . '/mimetypemapping.dist.json ' ), true );
167-
168- //Check if need to load custom mappings
169- if (file_exists ($ this ->customConfigDir . '/ ' . self ::CUSTOM_MIMETYPEMAPPING )) {
170- $ custom = json_decode (file_get_contents ($ this ->customConfigDir . '/ ' . self ::CUSTOM_MIMETYPEMAPPING ), true );
171- if (json_last_error () === JSON_ERROR_NONE ) {
172- $ mimetypeMapping = array_merge ($ mimetypeMapping , $ custom );
173- } else {
174- $ this ->logger ->warning ('Failed to parse ' . self ::CUSTOM_MIMETYPEMAPPING . ': ' . json_last_error_msg ());
175- }
176- }
170+ $ this ->loadCustomDefinitions (self ::CUSTOM_MIMETYPEMAPPING , $ mimetypeMapping );
177171
178172 $ this ->registerTypeArray ($ mimetypeMapping );
179173 }
0 commit comments