Prechádzať zdrojové kódy

[HttpFoundation] UploadedFile::getOriginalName is now overriding getName

Jordi Boggiano 14 rokov pred
rodič
commit
991b1ed225

+ 1 - 1
src/Symfony/Component/Form/FileField.php

@@ -90,7 +90,7 @@ class FileField extends Form
                 default:
                     $data['file']->move($this->getTmpDir());
                     $data['file']->rename($this->getTmpName($data['token']));
-                    $data['original_name'] = $data['file']->getOriginalName();
+                    $data['original_name'] = $data['file']->getName();
                     $data['file'] = '';
                     break;
             }

+ 10 - 5
src/Symfony/Component/HttpFoundation/File/UploadedFile.php

@@ -2,7 +2,7 @@
 
 /*
  * 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
@@ -101,13 +101,18 @@ class UploadedFile extends File
     }
 
     /**
-     * Returns the original file name including its extension.
+     * Returns the absolute file name without dots
+     *
+     * Until the uploaded file is moved, it will return the name of the temporary file
      *
-     * @returns string  The file name
+     * @returns string  The file path
      */
-    public function getOriginalName()
+    public function getName()
     {
-        return $this->originalName;
+        if (!$this->moved) {
+            return $this->originalName;
+        }
+        return parent::getName();
     }
 
     /**

+ 1 - 1
tests/Symfony/Tests/Component/Form/FileFieldTest.php

@@ -70,7 +70,7 @@ class FileFieldTest extends \PHPUnit_Framework_TestCase
                 $that->createTmpFile($tmpPath);
              }));
         $file->expects($this->any())
-             ->method('getOriginalName')
+             ->method('getName')
              ->will($this->returnValue('original_name.jpg'));
 
         $this->field->submit(array(

+ 1 - 1
tests/Symfony/Tests/Component/HttpFoundation/File/UploadedFileTest.php

@@ -95,7 +95,7 @@ class UploadedFileTest extends \PHPUnit_Framework_TestCase
                 null
             );
 
-            $this->assertEquals('original.gif', $file->getOriginalName());
+            $this->assertEquals('original.gif', $file->getName());
         }
     }
 }