Fix Mime type guessing
Cette révision appartient à :
Parent
3c3ffa8093
révision
a17b3d7e5e
@ -1,11 +1,12 @@
|
||||
<?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
|
||||
*/
|
||||
class ExtensionMimeTypeGuesser implements MimeTypeGuesserInterface
|
||||
class ExtensionMimeTypeGuesser implements FileMimeTypeGuesserInterface, MimeTypeGuesserInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
@ -22,4 +23,20 @@ class ExtensionMimeTypeGuesser implements MimeTypeGuesserInterface
|
||||
return "application/javascript";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isGuesserSupported(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function guessMimeType(string $path): ?string
|
||||
{
|
||||
return $this->guess($path);
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ use Symfony\Component\Console\Output\NullOutput;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;
|
||||
use Symfony\Component\Mime\MimeTypes;
|
||||
use Todaymade\Daux\Daux;
|
||||
use Todaymade\Daux\DauxHelper;
|
||||
use Todaymade\Daux\Exception;
|
||||
@ -97,7 +97,8 @@ class Server
|
||||
*/
|
||||
public function createResponse(Page $page) {
|
||||
|
||||
MimeTypeGuesser::getInstance()->register(new ExtensionMimeTypeGuesser);
|
||||
$mimeTypes = MimeTypes::getDefault();
|
||||
$mimeTypes->registerGuesser(new ExtensionMimeTypeGuesser());
|
||||
|
||||
if ($page instanceof RawPage) {
|
||||
return new BinaryFileResponse($page->getFile());
|
||||
|
Chargement…
Référencer dans un nouveau ticket
Block a user