diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2015-07-20 12:28:36 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2015-07-27 14:59:49 +0200 |
commit | d276aebf4099acd54dff7e727e25d28debf441b8 (patch) | |
tree | f0a68cbf002d4e2891853950cb725bff7219d4c9 /lib | |
parent | 88fb389eab368a9822e808eeffc23c4e1d2544e4 (diff) | |
download | nextcloud-server-d276aebf4099acd54dff7e727e25d28debf441b8.tar.gz nextcloud-server-d276aebf4099acd54dff7e727e25d28debf441b8.zip |
Pass config dir as parameter to detection class
In order to properly test the mimetype function:
* constructor takes path to configdir
* Added unit tests for mimetype (only if vfsStream is available)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/files/type/detection.php | 19 | ||||
-rw-r--r-- | lib/private/server.php | 4 |
2 files changed, 15 insertions, 8 deletions
diff --git a/lib/private/files/type/detection.php b/lib/private/files/type/detection.php index 7c6c87250e2..ba286637df3 100644 --- a/lib/private/files/type/detection.php +++ b/lib/private/files/type/detection.php @@ -47,11 +47,16 @@ class Detection implements IMimeTypeDetector { /** @var IURLGenerator */ private $urlGenerator; + /** @var string */ + private $configDir; + /** * @param IURLGenerator $urlGenerator + * @param string $configDir */ - public function __construct(IURLGenerator $urlGenerator) { + public function __construct(IURLGenerator $urlGenerator, $configDir) { $this->urlGenerator = $urlGenerator; + $this->configDir = $configDir; } /** @@ -96,11 +101,11 @@ class Detection implements IMimeTypeDetector { return; } - $file = file_get_contents(\OC::$configDir . '/mimetypealiases.dist.json'); + $file = file_get_contents($this->configDir . '/mimetypealiases.dist.json'); $this->mimeTypeAlias = get_object_vars(json_decode($file)); - if (file_exists(\OC::$configDir . '/mimetypealiases.json')) { - $custom = get_object_vars(json_decode(file_get_contents(\OC::$configDir . '/mimetypealiases.json'))); + if (file_exists($this->configDir . '/mimetypealiases.json')) { + $custom = get_object_vars(json_decode(file_get_contents($this->configDir . '/mimetypealiases.json'))); $this->mimeTypeAlias = array_merge($this->mimeTypeAlias, $custom); } } @@ -113,12 +118,12 @@ class Detection implements IMimeTypeDetector { return; } - $dist = file_get_contents(\OC::$configDir . '/mimetypemapping.dist.json'); + $dist = file_get_contents($this->configDir . '/mimetypemapping.dist.json'); $mimetypemapping = get_object_vars(json_decode($dist)); //Check if need to load custom mappings - if (file_exists(\OC::$configDir . '/mimetypemapping.json')) { - $custom = file_get_contents(\OC::$configDir . '/mimetypemapping.json'); + if (file_exists($this->configDir . '/mimetypemapping.json')) { + $custom = file_get_contents($this->configDir . '/mimetypemapping.json'); $custom_mapping = get_object_vars(json_decode($custom)); $mimetypemapping = array_merge($mimetypemapping, $custom_mapping); } diff --git a/lib/private/server.php b/lib/private/server.php index 82b2d6765dc..12981fe7f19 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -445,7 +445,9 @@ class Server extends SimpleContainer implements IServerContainer { return new \OC\Files\Mount\Manager(); }); $this->registerService('MimeTypeDetector', function(Server $c) { - return new \OC\Files\Type\Detection($c->getURLGenerator()); + return new \OC\Files\Type\Detection( + $c->getURLGenerator(), + \OC::$configDir); }); } |