瀏覽代碼

[HttpFoundation] removed the leading . for extensions

Fabien Potencier 14 年之前
父節點
當前提交
1e8cd6d34d

+ 3 - 0
UPDATE.md

@@ -9,6 +9,9 @@ timeline closely anyway.
 beta4 to beta5
 --------------
 
+* The `Symfony\Component\HttpFoundation\File\File::getExtension()` and
+  `guessExtension()` methods do not return the extension with a `.` anymore.
+
 * The `em` option of the Doctrine `EntityType` class now takes the entity
   manager name instead of the EntityManager instance. If you don't pass this
   option, the default Entity Manager will be used as before.

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

@@ -484,21 +484,21 @@ class File
     }
 
     /**
-     * Returns the file extension (with dot).
+     * Returns the file extension.
      *
      * @return string
      */
     public function getExtension()
     {
         if ($ext = pathinfo($this->getName(), PATHINFO_EXTENSION)) {
-            return '.'.$ext;
+            return $ext;
         }
 
         return '';
     }
 
     /**
-     * Returns the extension based on the mime type (with dot).
+     * Returns the extension based on the mime type.
      *
      * If the mime type is unknown, returns null.
      *
@@ -509,7 +509,7 @@ class File
         $type = $this->getMimeType();
 
         if (isset(self::$defaultExtensions[$type])) {
-            return '.'.self::$defaultExtensions[$type];
+            return self::$defaultExtensions[$type];
         }
 
         return null;

+ 1 - 1
src/Symfony/Component/HttpFoundation/File/UploadedFile.php

@@ -116,7 +116,7 @@ class UploadedFile extends File
         }
 
         if ($ext = pathinfo($this->getOriginalName(), PATHINFO_EXTENSION)) {
-            return '.'.$ext;
+            return $ext;
         }
 
         return '';

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

@@ -47,7 +47,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
 
     public function testGetExtensionReturnsExtensionWithDot()
     {
-        $this->assertEquals('.gif', $this->file->getExtension());
+        $this->assertEquals('gif', $this->file->getExtension());
     }
 
     public function testGetDirectoryReturnsDirectoryName()
@@ -78,7 +78,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
 
         MimeTypeGuesser::getInstance()->register($guesser);
 
-        $this->assertEquals('.gif', $file->guessExtension());
+        $this->assertEquals('gif', $file->guessExtension());
     }
 
     public function testConstructWhenFileNotExists()