[HttpFoundation] made FileBinaryMimeTypeGuesser command configurable

This commit is contained in:
Fabien Potencier 2011-09-14 09:45:15 +02:00
parent f9ecdfeb05
commit c5e0c80a76
2 changed files with 19 additions and 1 deletions

View File

@ -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

View File

@ -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();