diff --git a/src/MemoryAdapter.php b/src/MemoryAdapter.php index 1331380..f5fe0e3 100644 --- a/src/MemoryAdapter.php +++ b/src/MemoryAdapter.php @@ -105,7 +105,8 @@ public function getMetadata($path) */ public function getMimetype($path) { - $mimetype = Util::guessMimeType($path, $this->storage[$path]['contents']); + $mimetype = isset($this->storage[$path]['mimetype']) ? $this->storage[$path]['mimetype'] : + Util::guessMimeType($path, $this->storage[$path]['contents']); return [ 'mimetype' => $mimetype, @@ -223,6 +224,9 @@ public function update($path, $contents, Config $config) $this->storage[$path]['timestamp'] = $config->get('timestamp', time()); $this->storage[$path]['size'] = Util::contentSize($contents); $this->storage[$path]['visibility'] = $config->get('visibility', $this->storage[$path]['visibility']); + if ($config->has('mimetype')) { + $this->storage[$path]['mimetype'] = $config->get('mimetype'); + } return $this->getMetadata($path); } diff --git a/tests/MemoryAdapterTest.php b/tests/MemoryAdapterTest.php index a53b206..640a9a4 100644 --- a/tests/MemoryAdapterTest.php +++ b/tests/MemoryAdapterTest.php @@ -82,12 +82,24 @@ public function testGetMetadata() $this->assertSame(8, $meta['size']); $this->assertSame('public', $meta['visibility']); $this->assertTrue(is_int($meta['timestamp'])); + + $this->adapter->write('dir/file.txt', '', new Config(['mimetype' => 'mime/type'])); + + $meta = $this->adapter->getMetadata('dir/file.txt'); + + $this->assertCount(6, $meta); + $this->assertSame('mime/type', $meta['mimetype']); } public function testGetMimetype() { + $this->adapter->write('dir/file.txt', 'contents', new Config(['mimetype' => 'mime/type'])); + $meta = $this->adapter->getMimetype('file.txt'); $this->assertSame('text/plain', $meta['mimetype']); + + $meta = $this->adapter->getMimetype('dir/file.txt'); + $this->assertSame('mime/type', $meta['mimetype']); } public function testGetSize()