merged branch stealth35/mime_guesser (PR #1874)
Commits
-------
ea0db2d
[HttpFoundation] Remove useless ContentTypeMimeTypeGuesser
Discussion
----------
[2.1] [HttpFoundation] Remove useless ContentTypeMimeTypeGuesser
`mime_content_type` exists just for the compat between the old PHP 5.2
`mime_magic` extension and `file_info` extension
---------------------------------------------------------------------------
by fabpot at 2011/08/19 05:31:25 -0700
I will merge it in 2.1 as some people might rely on it.
---------------------------------------------------------------------------
by stealth35 at 2011/08/19 05:46:02 -0700
ok in the meantime, we can invert the guesser checker :
```php
/**
* Registers all natively provided mime type guessers
*/
private function __construct()
{
if (FileBinaryMimeTypeGuesser::isSupported()) {
$this->register(new FileBinaryMimeTypeGuesser());
}
if (FileinfoMimeTypeGuesser::isSupported()) {
$this->register(new FileinfoMimeTypeGuesser());
}
if (ContentTypeMimeTypeGuesser::isSupported()) {
$this->register(new ContentTypeMimeTypeGuesser());
}
}
```
---------------------------------------------------------------------------
by stloyd at 2011/08/19 05:48:38 -0700
@stealth35 You should make new PR for change you mentioned above.
---------------------------------------------------------------------------
by stealth35 at 2011/08/19 05:53:12 -0700
@stloyd done PR #1989
EDIT : forget this
This commit is contained in:
commit
2ccee10c51
@ -1,62 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpFoundation\File\MimeType;
|
||||
|
||||
use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
|
||||
use Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException;
|
||||
|
||||
/**
|
||||
* Guesses the mime type using the PHP function mime_content_type().
|
||||
*
|
||||
* @author Bernhard Schussek <bernhard.schussek@symfony.com>
|
||||
*/
|
||||
class ContentTypeMimeTypeGuesser implements MimeTypeGuesserInterface
|
||||
{
|
||||
/**
|
||||
* Returns whether this guesser is supported on the current OS/PHP setup
|
||||
*
|
||||
* @return Boolean
|
||||
*/
|
||||
static public function isSupported()
|
||||
{
|
||||
return function_exists('mime_content_type');
|
||||
}
|
||||
|
||||
/**
|
||||
* Guesses the mime type of the file with the given path
|
||||
*
|
||||
* @see MimeTypeGuesserInterface::guess()
|
||||
*/
|
||||
public function guess($path)
|
||||
{
|
||||
if (!is_file($path)) {
|
||||
throw new FileNotFoundException($path);
|
||||
}
|
||||
|
||||
if (!is_readable($path)) {
|
||||
throw new AccessDeniedException($path);
|
||||
}
|
||||
|
||||
if (!self::isSupported()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$type = mime_content_type($path);
|
||||
|
||||
// remove charset (added as of PHP 5.3)
|
||||
if (false !== $pos = strpos($type, ';')) {
|
||||
$type = substr($type, 0, $pos);
|
||||
}
|
||||
|
||||
return $type;
|
||||
}
|
||||
}
|
@ -67,10 +67,6 @@ class MimeTypeGuesser implements MimeTypeGuesserInterface
|
||||
$this->register(new FileBinaryMimeTypeGuesser());
|
||||
}
|
||||
|
||||
if (ContentTypeMimeTypeGuesser::isSupported()) {
|
||||
$this->register(new ContentTypeMimeTypeGuesser());
|
||||
}
|
||||
|
||||
if (FileinfoMimeTypeGuesser::isSupported()) {
|
||||
$this->register(new FileinfoMimeTypeGuesser());
|
||||
}
|
||||
|
@ -38,17 +38,6 @@ class MimeTypeTest extends \PHPUnit_Framework_TestCase
|
||||
MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/directory');
|
||||
}
|
||||
|
||||
public function testGuessImageWithContentTypeMimeTypeGuesser()
|
||||
{
|
||||
$guesser = MimeTypeGuesser::getInstance();
|
||||
$guesser->register(new ContentTypeMimeTypeGuesser());
|
||||
if (extension_loaded('fileinfo')) {
|
||||
$this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test'));
|
||||
} else {
|
||||
$this->assertNull(MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test'));
|
||||
}
|
||||
}
|
||||
|
||||
public function testGuessImageWithFileBinaryMimeTypeGuesser()
|
||||
{
|
||||
$guesser = MimeTypeGuesser::getInstance();
|
||||
|
Reference in New Issue
Block a user