Skip to content

Commit

Permalink
[HttpFoundation] made FileBinaryMimeTypeGuesser command configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Sep 14, 2011
1 parent f9ecdfe commit c5e0c80
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG-2.1.md
Expand Up @@ -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
Expand Down
Expand Up @@ -21,6 +21,23 @@
*/
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
*
Expand Down Expand Up @@ -52,7 +69,7 @@ public function guess($path)
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();

Expand Down

0 comments on commit c5e0c80

Please sign in to comment.