Skip to content

Set MIME type based on requested asset #202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public function testCollectDirectory()
{
$alias = 'my/alias/';
$resolver = new AliasPathStackResolver(array($alias => realpath(__DIR__ . '/../')));
$dir = substr(__DIR__, strrpos(__DIR__, '/', 0) + 1);
$dir = substr(__DIR__, strrpos(__DIR__, DIRECTORY_SEPARATOR, 0) + 1);

$this->assertContains($alias . $dir . DIRECTORY_SEPARATOR . basename(__FILE__), $resolver->collect());
$this->assertNotContains($alias . $dir . DIRECTORY_SEPARATOR . 'i-do-not-exist.php', $resolver->collect());
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
2 changes: 1 addition & 1 deletion tests/AssetManagerTest/Resolver/PathStackResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function testCollectDirectory()
{
$resolver = new PathStackResolver();
$resolver->addPath(realpath(__DIR__ . '/../'));
$dir = substr(__DIR__, strrpos(__DIR__, '/', 0) + 1);
$dir = substr(__DIR__, strrpos(__DIR__, DIRECTORY_SEPARATOR, 0) + 1);

$this->assertContains($dir . DIRECTORY_SEPARATOR . basename(__FILE__), $resolver->collect());
$this->assertNotContains($dir . DIRECTORY_SEPARATOR . 'i-do-not-exist.php', $resolver->collect());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public function testCollectDirectory()
{
$resolver = new PrioritizedPathsResolver();
$resolver->addPath(realpath(__DIR__ . '/../'));
$dir = substr(__DIR__, strrpos(__DIR__, '/', 0) + 1);
$dir = substr(__DIR__, strrpos(__DIR__, DIRECTORY_SEPARATOR, 0) + 1);

$this->assertContains($dir . DIRECTORY_SEPARATOR . basename(__FILE__), $resolver->collect());
$this->assertNotContains($dir . DIRECTORY_SEPARATOR . 'i-do-not-exist.php', $resolver->collect());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public function testCreateService()
$resolver = $factory->createService($serviceManager);
$this->assertSame(
array(
'path2/',
'path1/',
'path2' . DIRECTORY_SEPARATOR,
'path1' . DIRECTORY_SEPARATOR,
),
$resolver->getPaths()->toArray()
);
Expand Down