diff options
author | Daniel Kesselberg <mail@danielkesselberg.de> | 2019-12-08 22:16:25 +0100 |
---|---|---|
committer | Daniel Kesselberg <mail@danielkesselberg.de> | 2019-12-09 12:10:19 +0100 |
commit | 29575c4d362570d10a43935fda7e3918a69f47c3 (patch) | |
tree | a1ae2aa753ae58cdecdbd3c7c7e97ca5dc0cbc94 /lib | |
parent | 64aba49461114b986952ece89ea9467618a0ab19 (diff) | |
download | nextcloud-server-29575c4d362570d10a43935fda7e3918a69f47c3.tar.gz nextcloud-server-29575c4d362570d10a43935fda7e3918a69f47c3.zip |
Move custom definition logic into method
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Files/Type/Detection.php | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/lib/private/Files/Type/Detection.php b/lib/private/Files/Type/Detection.php index f58431efee5..8505f59bacc 100644 --- a/lib/private/Files/Type/Detection.php +++ b/lib/private/Files/Type/Detection.php @@ -47,8 +47,8 @@ use OCP\IURLGenerator; */ class Detection implements IMimeTypeDetector { - public const CUSTOM_MIMETYPEMAPPING = 'mimetypemapping.json'; - public const CUSTOM_MIMETYPEALIASES = 'mimetypealiases.json'; + private const CUSTOM_MIMETYPEMAPPING = 'mimetypemapping.json'; + private const CUSTOM_MIMETYPEALIASES = 'mimetypealiases.json'; protected $mimetypes = []; protected $secureMimeTypes = []; @@ -121,6 +121,18 @@ class Detection implements IMimeTypeDetector { } } + private function loadCustomDefinitions(string $fileName, array $definitions): array { + if (file_exists($this->customConfigDir . '/' . $fileName)) { + $custom = json_decode(file_get_contents($this->customConfigDir . '/' . $fileName), true); + if (json_last_error() === JSON_ERROR_NONE) { + $definitions = array_merge($definitions, $custom); + } else { + $this->logger->warning('Failed to parse ' . $fileName . ': ' . json_last_error_msg()); + } + } + return $definitions; + } + /** * Add the mimetype aliases if they are not yet present */ @@ -130,15 +142,7 @@ class Detection implements IMimeTypeDetector { } $this->mimeTypeAlias = json_decode(file_get_contents($this->defaultConfigDir . '/mimetypealiases.dist.json'), true); - - if (file_exists($this->customConfigDir . '/' . self::CUSTOM_MIMETYPEALIASES)) { - $custom = json_decode(file_get_contents($this->customConfigDir . '/' . self::CUSTOM_MIMETYPEALIASES), true); - if (json_last_error() === JSON_ERROR_NONE) { - $this->mimeTypeAlias = array_merge($this->mimeTypeAlias, $custom); - } else { - $this->logger->warning('Failed to parse ' . self::CUSTOM_MIMETYPEALIASES . ': ' . json_last_error_msg()); - } - } + $this->mimeTypeAlias = $this->loadCustomDefinitions(self::CUSTOM_MIMETYPEALIASES, $this->mimeTypeAlias); } /** @@ -164,16 +168,7 @@ class Detection implements IMimeTypeDetector { } $mimetypeMapping = json_decode(file_get_contents($this->defaultConfigDir . '/mimetypemapping.dist.json'), true); - - //Check if need to load custom mappings - if (file_exists($this->customConfigDir . '/' . self::CUSTOM_MIMETYPEMAPPING)) { - $custom = json_decode(file_get_contents($this->customConfigDir . '/' . self::CUSTOM_MIMETYPEMAPPING), true); - if (json_last_error() === JSON_ERROR_NONE) { - $mimetypeMapping = array_merge($mimetypeMapping, $custom); - } else { - $this->logger->warning('Failed to parse ' . self::CUSTOM_MIMETYPEMAPPING . ': ' . json_last_error_msg()); - } - } + $mimetypeMapping = $this->loadCustomDefinitions(self::CUSTOM_MIMETYPEMAPPING, $mimetypeMapping); $this->registerTypeArray($mimetypeMapping); } |