8000 [HttpFoundation] Incorrect documentation and method name for Uploaded… · symfony/symfony@eb469dc · GitHub
[go: up one dir, main page]

Skip to content

Commit eb469dc

Browse files
author
Amrouche Hamza
committed
[HttpFoundation] Incorrect documentation and method name for UploadedFile::getClientSize()
1 parent 8e7eac6 commit eb469dc

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

src/Symfony/Component/HttpFoundation/File/UploadedFile.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,26 @@ public function guessClientExtension()
141141
* It is extracted from the request from which the file has been uploaded.
142142
* Then it should not be considered as a safe value.
143143
*
144-
* @return int|null The file size
144+
* @deprecated since 4.1 will be removed in 5.0 use getFileSize instead.
145+
*
146+
* @return int|null The file sizes
145147
*/
146148
public function getClientSize()
149+
{
150+
@trigger_error(sprintf('%s is deprecated since 4.1 and will be removed in 5.0 use %s instead.', __METHOD__, 'getFileSize'), E_USER_DEPRECATED);
151+
152+
return $this->size;
153+
}
154+
155+
/**
156+
* Returns the file size.
157+
*
158+
* It is calculated from $_FILES['fileupload']['size'] which is computed by PHP.
159+
* Then it should be considered as a safe value.
160+
*
161+
* @return int|null The file size
162+
*/
163+
public function getFileSize()
147164
{
148165
return $this->size;
149166
}

src/Symfony/Component/HttpFoundation/Tests/File/UploadedFileTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,19 @@ public function testGetSize()
206206
$this->assertEquals(filesize(__DIR__.'/Fixtures/test'), $file->getSize());
207207
}
208208

209+
public function testGetFileSize()
210+
{
211+
$file = new UploadedFile(
212+
__DIR__.'/Fixtures/test.gif',
213+
'original.gif',
214+
'image/gif',
215+
filesize(__DIR__.'/Fixtures/test.gif'),
216+
null
217+
);
218+
219+
$this->assertEquals(filesize(__DIR__.'/Fixtures/test.gif'), $file->getFileSize());
220+
}
221+
209222
public function testGetExtension()
210223
{
211224
$file = new UploadedFile(

src/Symfony/Component/HttpKernel/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ protected function filterFiles(array $files)
177177
$value->getPathname(),
178178
$value->getClientOriginalName(),
179179
$value->getClientMimeType(),
180-
$value->getClientSize(),
180+
$value->getFileSize(),
181181
$value->getError(),
182182
true
183183
);

src/Symfony/Component/HttpKernel/Tests/ClientTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function testUploadedFile()
120120

121121
$this->assertEquals('original', $file->getClientOriginalName());
122122
$this->assertEquals('mime/original', $file->getClientMimeType());
123-
$this->assertEquals('123', $file->getClientSize());
123+
$this->assertEquals('123', $file->getFileSize());
124124
$this->assertTrue($file->isValid());
125125
}
126126

@@ -176,7 +176,7 @@ public function testUploadedFileWhenSizeExceedsUploadMaxFileSize()
176176
$this->assertEquals(UPLOAD_ERR_INI_SIZE, $file->getError());
177177
$this->assertEquals('mime/original', $file->getClientMimeType());
178178
$this->assertEquals('original', $file->getClientOriginalName());
179-
$this->assertEquals(0, $file->getClientSize());
179+
$this->assertEquals(0, $file->getFileSize());
180180

181181
unlink($source);
182182
}

0 commit comments

Comments
 (0)
0