package and depencies
This commit is contained in:
@@ -13,7 +13,7 @@ namespace Symfony\Component\HttpFoundation\File\Exception;
|
||||
|
||||
class UnexpectedTypeException extends FileException
|
||||
{
|
||||
public function __construct($value, string $expectedType)
|
||||
public function __construct(mixed $value, string $expectedType)
|
||||
{
|
||||
parent::__construct(sprintf('Expected argument of type %s, %s given', $expectedType, get_debug_type($value)));
|
||||
}
|
||||
|
21
vendor/symfony/http-foundation/File/File.php
vendored
21
vendor/symfony/http-foundation/File/File.php
vendored
@@ -47,12 +47,10 @@ class File extends \SplFileInfo
|
||||
* This method uses the mime type as guessed by getMimeType()
|
||||
* to guess the file extension.
|
||||
*
|
||||
* @return string|null
|
||||
*
|
||||
* @see MimeTypes
|
||||
* @see getMimeType()
|
||||
*/
|
||||
public function guessExtension()
|
||||
public function guessExtension(): ?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".');
|
||||
@@ -68,11 +66,9 @@ class File extends \SplFileInfo
|
||||
* which uses finfo_file() then the "file" system binary,
|
||||
* depending on which of those are available.
|
||||
*
|
||||
* @return string|null
|
||||
*
|
||||
* @see MimeTypes
|
||||
*/
|
||||
public function getMimeType()
|
||||
public function getMimeType(): ?string
|
||||
{
|
||||
if (!class_exists(MimeTypes::class)) {
|
||||
throw new \LogicException('You cannot guess the mime type as the Mime component is not installed. Try running "composer require symfony/mime".');
|
||||
@@ -84,11 +80,9 @@ class File extends \SplFileInfo
|
||||
/**
|
||||
* Moves the file to a new location.
|
||||
*
|
||||
* @return self
|
||||
*
|
||||
* @throws FileException if the target file could not be created
|
||||
*/
|
||||
public function move(string $directory, string $name = null)
|
||||
public function move(string $directory, string $name = null): self
|
||||
{
|
||||
$target = $this->getTargetFile($directory, $name);
|
||||
|
||||
@@ -118,10 +112,7 @@ class File extends \SplFileInfo
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return self
|
||||
*/
|
||||
protected function getTargetFile(string $directory, string $name = null)
|
||||
protected function getTargetFile(string $directory, string $name = null): self
|
||||
{
|
||||
if (!is_dir($directory)) {
|
||||
if (false === @mkdir($directory, 0777, true) && !is_dir($directory)) {
|
||||
@@ -138,10 +129,8 @@ class File extends \SplFileInfo
|
||||
|
||||
/**
|
||||
* Returns locale independent base name of the given path.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getName(string $name)
|
||||
protected function getName(string $name): string
|
||||
{
|
||||
$originalName = str_replace('\\', '/', $name);
|
||||
$pos = strrpos($originalName, '/');
|
||||
|
@@ -18,13 +18,7 @@ namespace Symfony\Component\HttpFoundation\File;
|
||||
*/
|
||||
class Stream extends File
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return int|false
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function getSize()
|
||||
public function getSize(): int|false
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@@ -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