Browse Source

[HttpFoundation] renamed getDefaultExtension() to guessExtension()

The renamed method now returns null if it cannot guess the extension. It allows
the developper to know whether the extension has been guessed or not.
Fabien Potencier 14 năm trước cách đây
mục cha
commit
5bb9da4b6d

+ 4 - 4
src/Symfony/Component/HttpFoundation/File/File.php

@@ -500,11 +500,11 @@ class File
     /**
      * Returns the extension based on the mime type (with dot).
      *
-     * If the mime type is unknown, the actual extension is returned instead.
+     * If the mime type is unknown, returns null.
      *
-     * @return string
+     * @return string|null The guessed extension or null if it cannot be guessed
      */
-    public function getDefaultExtension()
+    public function guessExtension()
     {
         $type = $this->getMimeType();
 
@@ -512,7 +512,7 @@ class File
             return '.'.self::$defaultExtensions[$type];
         }
 
-        return $this->getExtension();
+        return null;
     }
 
     /**

+ 4 - 4
tests/Symfony/Tests/Component/HttpFoundation/File/FileTest.php

@@ -63,21 +63,21 @@ class FileTest extends \PHPUnit_Framework_TestCase
         $this->assertEquals('image/gif', $this->file->getMimeType());
     }
 
-    public function testGetDefaultExtensionWithoutGuesser()
+    public function testGuessExtensionWithoutGuesser()
     {
         $file = new File(__DIR__.'/Fixtures/directory/.empty');
 
-        $this->assertEquals('.empty', $file->getDefaultExtension());
+        $this->assertEquals(null, $file->guessExtension());
     }
 
-    public function testGetDefaultExtensionIsBasedOnMimeType()
+    public function testGuessExtensionIsBasedOnMimeType()
     {
         $file = new File(__DIR__.'/Fixtures/test');
         $guesser = $this->createMockGuesser($file->getPath(), 'image/gif');
 
         MimeTypeGuesser::getInstance()->register($guesser);
 
-        $this->assertEquals('.gif', $file->getDefaultExtension());
+        $this->assertEquals('.gif', $file->guessExtension());
     }
 
     public function testConstructWhenFileNotExists()