From c5e0c80a76e78994e0d6e6fed07091c01349a04c Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 14 Sep 2011 09:45:15 +0200 Subject: [PATCH] [HttpFoundation] made FileBinaryMimeTypeGuesser command configurable --- CHANGELOG-2.1.md | 1 + .../MimeType/FileBinaryMimeTypeGuesser.php | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG-2.1.md b/CHANGELOG-2.1.md index 11af5c97a2..c148a68020 100644 --- a/CHANGELOG-2.1.md +++ b/CHANGELOG-2.1.md @@ -24,6 +24,7 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c ### HttpFoundation + * made FileBinaryMimeTypeGuesser command configurable * added Request::getUser() and Request::getPassword() * added support for the PATCH method in Request * removed the ContentTypeMimeTypeGuesser class as it is deprecated and never used on PHP 5.3 diff --git a/src/Symfony/Component/HttpFoundation/File/MimeType/FileBinaryMimeTypeGuesser.php b/src/Symfony/Component/HttpFoundation/File/MimeType/FileBinaryMimeTypeGuesser.php index 1b869f22cb..8b242ad4e4 100644 --- a/src/Symfony/Component/HttpFoundation/File/MimeType/FileBinaryMimeTypeGuesser.php +++ b/src/Symfony/Component/HttpFoundation/File/MimeType/FileBinaryMimeTypeGuesser.php @@ -21,6 +21,23 @@ use Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException; */ class FileBinaryMimeTypeGuesser implements MimeTypeGuesserInterface { + private $cmd; + + /** + * Constructor. + * + * The $cmd pattern must contain a "%s" string that will be replaced + * with the file name to guess. + * + * The command output must start with the mime type of the file. + * + * @param string $cmd The command to run to get the mime type of a file + */ + public function __construct($cmd = 'file -b --mime %s 2>/dev/null') + { + $this->cmd = $cmd; + } + /** * Returns whether this guesser is supported on the current OS * @@ -52,7 +69,7 @@ class FileBinaryMimeTypeGuesser implements MimeTypeGuesserInterface ob_start(); // need to use --mime instead of -i. see #6641 - passthru(sprintf('file -b --mime %s 2>/dev/null', escapeshellarg($path)), $return); + passthru(sprintf($this->cmd, escapeshellarg($path)), $return); if ($return > 0) { ob_end_clean();