package and depencies
This commit is contained in:
@@ -31,10 +31,10 @@ use Symfony\Component\Mime\MimeTypes;
|
||||
*/
|
||||
class UploadedFile extends File
|
||||
{
|
||||
private $test;
|
||||
private $originalName;
|
||||
private $mimeType;
|
||||
private $error;
|
||||
private bool $test;
|
||||
private string $originalName;
|
||||
private string $mimeType;
|
||||
private int $error;
|
||||
|
||||
/**
|
||||
* Accepts the information of the uploaded file as provided by the PHP global $_FILES.
|
||||
@@ -75,10 +75,8 @@ class UploadedFile extends File
|
||||
*
|
||||
* It is extracted from the request from which the file has been uploaded.
|
||||
* Then it should not be considered as a safe value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getClientOriginalName()
|
||||
public function getClientOriginalName(): string
|
||||
{
|
||||
return $this->originalName;
|
||||
}
|
||||
@@ -88,10 +86,8 @@ class UploadedFile extends File
|
||||
*
|
||||
* It is extracted from the original file name that was uploaded.
|
||||
* Then it should not be considered as a safe value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getClientOriginalExtension()
|
||||
public function getClientOriginalExtension(): string
|
||||
{
|
||||
return pathinfo($this->originalName, \PATHINFO_EXTENSION);
|
||||
}
|
||||
@@ -105,11 +101,9 @@ class UploadedFile extends File
|
||||
* For a trusted mime type, use getMimeType() instead (which guesses the mime
|
||||
* type based on the file content).
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @see getMimeType()
|
||||
*/
|
||||
public function getClientMimeType()
|
||||
public function getClientMimeType(): string
|
||||
{
|
||||
return $this->mimeType;
|
||||
}
|
||||
@@ -126,12 +120,10 @@ class UploadedFile extends File
|
||||
* For a trusted extension, use guessExtension() instead (which guesses
|
||||
* the extension based on the guessed mime type for the file).
|
||||
*
|
||||
* @return string|null
|
||||
*
|
||||
* @see guessExtension()
|
||||
* @see getClientMimeType()
|
||||
*/
|
||||
public function guessClientExtension()
|
||||
public function guessClientExtension(): ?string
|
||||
{
|
||||
if (!class_exists(MimeTypes::class)) {
|
||||
throw new \LogicException('You cannot guess the extension as the Mime component is not installed. Try running "composer require symfony/mime".');
|
||||
@@ -145,20 +137,16 @@ class UploadedFile extends File
|
||||
*
|
||||
* If the upload was successful, the constant UPLOAD_ERR_OK is returned.
|
||||
* Otherwise one of the other UPLOAD_ERR_XXX constants is returned.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getError()
|
||||
public function getError(): int
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the file has been uploaded with HTTP and no error occurred.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isValid()
|
||||
public function isValid(): bool
|
||||
{
|
||||
$isOk = \UPLOAD_ERR_OK === $this->error;
|
||||
|
||||
@@ -168,11 +156,9 @@ class UploadedFile extends File
|
||||
/**
|
||||
* Moves the file to a new location.
|
||||
*
|
||||
* @return File
|
||||
*
|
||||
* @throws FileException if, for any reason, the file could not have been moved
|
||||
*/
|
||||
public function move(string $directory, string $name = null)
|
||||
public function move(string $directory, string $name = null): File
|
||||
{
|
||||
if ($this->isValid()) {
|
||||
if ($this->test) {
|
||||
@@ -221,7 +207,7 @@ class UploadedFile extends File
|
||||
*
|
||||
* @return int|float The maximum size of an uploaded file in bytes (returns float if size > PHP_INT_MAX)
|
||||
*/
|
||||
public static function getMaxFilesize()
|
||||
public static function getMaxFilesize(): int|float
|
||||
{
|
||||
$sizePostMax = self::parseFilesize(\ini_get('post_max_size'));
|
||||
$sizeUploadMax = self::parseFilesize(\ini_get('upload_max_filesize'));
|
||||
@@ -229,12 +215,7 @@ class UploadedFile extends File
|
||||
return min($sizePostMax ?: \PHP_INT_MAX, $sizeUploadMax ?: \PHP_INT_MAX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the given size from an ini value in bytes.
|
||||
*
|
||||
* @return int|float Returns float if size > PHP_INT_MAX
|
||||
*/
|
||||
private static function parseFilesize(string $size)
|
||||
private static function parseFilesize(string $size): int|float
|
||||
{
|
||||
if ('' === $size) {
|
||||
return 0;
|
||||
@@ -266,10 +247,8 @@ class UploadedFile extends File
|
||||
|
||||
/**
|
||||
* Returns an informative upload error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getErrorMessage()
|
||||
public function getErrorMessage(): string
|
||||
{
|
||||
static $errors = [
|
||||
\UPLOAD_ERR_INI_SIZE => 'The file "%s" exceeds your upload_max_filesize ini directive (limit is %d KiB).',
|
||||
|
Reference in New Issue
Block a user