Fix Mime type guessing

This commit is contained in:
DragoonBoots 2019-08-07 12:55:18 -04:00 committed by Stéphane Goetz
parent 3c3ffa8093
commit a17b3d7e5e
2 changed files with 22 additions and 4 deletions

View File

@ -1,11 +1,12 @@
<?php namespace Todaymade\Daux\Server; <?php namespace Todaymade\Daux\Server;
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface; use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface as FileMimeTypeGuesserInterface;
use Symfony\Component\Mime\MimeTypeGuesserInterface;
/** /**
* Guesses the mime type using the file's extension * Guesses the mime type using the file's extension
*/ */
class ExtensionMimeTypeGuesser implements MimeTypeGuesserInterface class ExtensionMimeTypeGuesser implements FileMimeTypeGuesserInterface, MimeTypeGuesserInterface
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}
@ -22,4 +23,20 @@ class ExtensionMimeTypeGuesser implements MimeTypeGuesserInterface
return "application/javascript"; return "application/javascript";
} }
} }
/**
* {@inheritdoc}
*/
public function isGuesserSupported(): bool
{
return true;
}
/**
* {@inheritdoc}
*/
public function guessMimeType(string $path): ?string
{
return $this->guess($path);
}
} }

View File

@ -4,7 +4,7 @@ use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser; use Symfony\Component\Mime\MimeTypes;
use Todaymade\Daux\Daux; use Todaymade\Daux\Daux;
use Todaymade\Daux\DauxHelper; use Todaymade\Daux\DauxHelper;
use Todaymade\Daux\Exception; use Todaymade\Daux\Exception;
@ -97,7 +97,8 @@ class Server
*/ */
public function createResponse(Page $page) { public function createResponse(Page $page) {
MimeTypeGuesser::getInstance()->register(new ExtensionMimeTypeGuesser); $mimeTypes = MimeTypes::getDefault();
$mimeTypes->registerGuesser(new ExtensionMimeTypeGuesser());
if ($page instanceof RawPage) { if ($page instanceof RawPage) {
return new BinaryFileResponse($page->getFile()); return new BinaryFileResponse($page->getFile());