From 8f6a2c54f2ff8ebca15ec2d33f2967119fa714d2 Mon Sep 17 00:00:00 2001 From: Renaat De Muynck Date: Fri, 18 Nov 2016 15:08:18 +0100 Subject: [PATCH] Set MIME type based on requested asset (fixes #200) --- src/AssetManager/Resolver/AliasPathStackResolver.php | 2 +- src/AssetManager/Resolver/ConcatResolver.php | 1 + src/AssetManager/Resolver/MapResolver.php | 2 +- src/AssetManager/Resolver/PathStackResolver.php | 2 +- src/AssetManager/Resolver/PrioritizedPathsResolver.php | 2 +- src/AssetManager/Service/MimeResolver.php | 8 ++++---- tests/AssetManagerTest/Resolver/MapResolverTest.php | 10 +++++----- 7 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/AssetManager/Resolver/AliasPathStackResolver.php b/src/AssetManager/Resolver/AliasPathStackResolver.php index 5ad1c3ea..aaa0cb7a 100644 --- a/src/AssetManager/Resolver/AliasPathStackResolver.php +++ b/src/AssetManager/Resolver/AliasPathStackResolver.php @@ -147,7 +147,7 @@ public function resolve($name) if ($file->isReadable() && !$file->isDir()) { $filePath = $file->getRealPath(); - $mimeType = $this->getMimeResolver()->getMimeType($filePath); + $mimeType = $this->getMimeResolver()->getMimeType($name); $asset = new FileAsset($filePath); $asset->mimetype = $mimeType; diff --git a/src/AssetManager/Resolver/ConcatResolver.php b/src/AssetManager/Resolver/ConcatResolver.php index 68b3b958..c43ef473 100644 --- a/src/AssetManager/Resolver/ConcatResolver.php +++ b/src/AssetManager/Resolver/ConcatResolver.php @@ -153,6 +153,7 @@ public function resolve($name) $aggregateAsset = new AggregateAsset($resolvedAssets); $this->getAssetFilterManager()->setFilters($name, $aggregateAsset); $aggregateAsset->setTargetPath($name); + $aggregateAsset->mimetype = $this->getMimeResolver()->getMimeType($name); return $aggregateAsset; } diff --git a/src/AssetManager/Resolver/MapResolver.php b/src/AssetManager/Resolver/MapResolver.php index e2b0cca0..bf7ec67f 100644 --- a/src/AssetManager/Resolver/MapResolver.php +++ b/src/AssetManager/Resolver/MapResolver.php @@ -101,7 +101,7 @@ public function resolve($name) } $file = $this->map[$name]; - $mimeType = $this->getMimeResolver()->getMimeType($file); + $mimeType = $this->getMimeResolver()->getMimeType($name); if (false === filter_var($file, FILTER_VALIDATE_URL)) { $asset = new FileAsset($file); diff --git a/src/AssetManager/Resolver/PathStackResolver.php b/src/AssetManager/Resolver/PathStackResolver.php index 10a6d39f..f71c52f4 100644 --- a/src/AssetManager/Resolver/PathStackResolver.php +++ b/src/AssetManager/Resolver/PathStackResolver.php @@ -181,7 +181,7 @@ public function resolve($name) if ($file->isReadable() && !$file->isDir()) { $filePath = $file->getRealPath(); - $mimeType = $this->getMimeResolver()->getMimeType($filePath); + $mimeType = $this->getMimeResolver()->getMimeType($name); $asset = new FileAsset($filePath); $asset->mimetype = $mimeType; diff --git a/src/AssetManager/Resolver/PrioritizedPathsResolver.php b/src/AssetManager/Resolver/PrioritizedPathsResolver.php index a1f7ced1..1059fe88 100644 --- a/src/AssetManager/Resolver/PrioritizedPathsResolver.php +++ b/src/AssetManager/Resolver/PrioritizedPathsResolver.php @@ -189,7 +189,7 @@ public function resolve($name) if ($file->isReadable() && !$file->isDir()) { $filePath = $file->getRealPath(); - $mimeType = $this->getMimeResolver()->getMimeType($filePath); + $mimeType = $this->getMimeResolver()->getMimeType($name); $asset = new FileAsset($filePath); $asset->mimetype = $mimeType; diff --git a/src/AssetManager/Service/MimeResolver.php b/src/AssetManager/Service/MimeResolver.php index cd19176f..3eabcbe6 100644 --- a/src/AssetManager/Service/MimeResolver.php +++ b/src/AssetManager/Service/MimeResolver.php @@ -88,7 +88,7 @@ class MimeResolver 'cmdf' => 'chemical/x-cmdf', 'cml' => 'chemical/x-cml', 'cod' => 'application/vnd.rim.cod', - 'coffee' => 'application/javascript', + 'coffee' => 'application/vnd.coffeescript', 'com' => 'application/x-msdos-program', 'cpa' => 'chemical/x-compass', 'cpio' => 'application/x-cpio', @@ -238,7 +238,7 @@ class MimeResolver 'kwd' => 'application/x-kword', 'kwt' => 'application/x-kword', 'latex' => 'application/x-latex', - 'less' => 'text/css', + 'less' => 'text/less', 'lha' => 'application/x-lha', 'lhs' => 'text/x-literate-haskell', 'lin' => 'application/bbolin', @@ -400,13 +400,13 @@ class MimeResolver 'rtf' => 'application/rtf', 'rtx' => 'text/richtext', 'rxn' => 'chemical/x-mdl-rxnfile', - 'sass' => 'text/css', + 'sass' => 'text/sass', 'scala' => 'text/x-scala', 'sce' => 'application/x-scilab', 'sci' => 'application/x-scilab', 'sco' => 'audio/csound', 'scr' => 'application/x-silverlight', - 'scss' => 'text/css', + 'scss' => 'text/scss', 'sct' => 'text/scriptlet', 'sd' => 'chemical/x-mdl-sdfile', 'sd2' => 'audio/x-sd2', diff --git a/tests/AssetManagerTest/Resolver/MapResolverTest.php b/tests/AssetManagerTest/Resolver/MapResolverTest.php index a9c78247..ebf0578f 100644 --- a/tests/AssetManagerTest/Resolver/MapResolverTest.php +++ b/tests/AssetManagerTest/Resolver/MapResolverTest.php @@ -107,12 +107,12 @@ public function testResolveAssetSuccess() $resolver->setMimeResolver($mimeResolver); $asset1 = array( - 'bacon' => __FILE__, + 'bacon.php' => __FILE__, ); $resolver->setMap($asset1); - $asset = $resolver->resolve('bacon'); + $asset = $resolver->resolve('bacon.php'); $mimetype = $mimeResolver->getMimeType(__FILE__); $this->assertTrue($asset instanceof Asset\FileAsset); @@ -127,18 +127,18 @@ public function testResolveHttpAssetSuccess() $mimeResolver->expects($this->any()) ->method('getMimeType') - ->with('http://foo.bar/') + ->with('bacon.bar') ->will($this->returnValue('text/foo')); $resolver->setMimeResolver($mimeResolver); $asset1 = array( - 'bacon' => 'http://foo.bar/', + 'bacon.bar' => 'http://foo.bar/', ); $resolver->setMap($asset1); - $asset = $resolver->resolve('bacon'); + $asset = $resolver->resolve('bacon.bar'); $this->assertTrue($asset instanceof Asset\HttpAsset); $this->assertSame('text/foo', $asset->mimetype);