Browse Source

[HttpFoundation] removed the leading . for extensions

Fabien Potencier 14 years ago
parent
commit
1e8cd6d34d

+ 3 - 0
UPDATE.md

@@ -9,6 +9,9 @@ timeline closely anyway.
 beta4 to beta5
 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
 * 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
   manager name instead of the EntityManager instance. If you don't pass this
   option, the default Entity Manager will be used as before.
   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
      * @return string
      */
      */
     public function getExtension()
     public function getExtension()
     {
     {
         if ($ext = pathinfo($this->getName(), PATHINFO_EXTENSION)) {
         if ($ext = pathinfo($this->getName(), PATHINFO_EXTENSION)) {
-            return '.'.$ext;
+            return $ext;
         }
         }
 
 
         return '';
         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.
      * If the mime type is unknown, returns null.
      *
      *
@@ -509,7 +509,7 @@ class File
         $type = $this->getMimeType();
         $type = $this->getMimeType();
 
 
         if (isset(self::$defaultExtensions[$type])) {
         if (isset(self::$defaultExtensions[$type])) {
-            return '.'.self::$defaultExtensions[$type];
+            return self::$defaultExtensions[$type];
         }
         }
 
 
         return null;
         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)) {
         if ($ext = pathinfo($this->getOriginalName(), PATHINFO_EXTENSION)) {
-            return '.'.$ext;
+            return $ext;
         }
         }
 
 
         return '';
         return '';

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

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