Skip to content

Commit

Permalink
Set MIME type based on requested asset (fixes RWOverdijk#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
renaatdemuynck committed Nov 18, 2016
1 parent ef3d05d commit 8f6a2c5
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/AssetManager/Resolver/AliasPathStackResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/AssetManager/Resolver/ConcatResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/AssetManager/Resolver/MapResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/AssetManager/Resolver/PathStackResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/AssetManager/Resolver/PrioritizedPathsResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/AssetManager/Service/MimeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
10 changes: 5 additions & 5 deletions tests/AssetManagerTest/Resolver/MapResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 8f6a2c5

Please sign in to comment.